<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <!-- hexo-inject:begin --><!-- hexo-inject:end --><meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222" media="(prefers-color-scheme: light)">
<meta name="theme-color" content="#222" media="(prefers-color-scheme: dark)"><meta name="generator" content="Hexo 5.4.2">

  <link rel="apple-touch-icon" sizes="180x180" href="https://static.xiaosige.com/img/favicon.png">
  <link rel="icon" type="image/png" sizes="32x32" href="https://static.xiaosige.com/img/favicon.png">
  <link rel="icon" type="image/png" sizes="16x16" href="https://static.xiaosige.com/img/favicon.png">
  <link rel="mask-icon" href="https://static.xiaosige.com/img/favicon.png" color="#222">
  <meta name="baidu-site-verification" content="WZilU4QiSZ">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.1/css/all.min.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui@5.0.31/dist/fancybox/fancybox.css" integrity="sha256-gkQVf8UKZgQ0HyuxL/VnacadJ+D2Kox2TCEBuNQg5+w=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"www.xiaosige.com","root":"/","images":"/images","scheme":"Gemini","darkmode":true,"version":"8.26.0","exturl":false,"sidebar":{"position":"left","width_expanded":320,"width_dual_column":240,"display":"post","padding":18,"offset":12},"hljswrap":false,"codeblock":{"theme":{"light":"atom-one-dark-reasonable","dark":"atom-one-dark-reasonable"},"prism":{"light":"prism-tomorrow","dark":"prism-tomorrow"},"copy_button":{"enable":true,"style":"mac"},"fold":{"enable":false,"height":500},"language":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":"changyan","storage":true,"lazyload":true,"nav":null,"activeClass":"changyan"},"stickytabs":false,"motion":{"enable":true,"async":false,"duration":200,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"top_n_per_article":1,"unescape":false,"preload":true,"trigger":"auto"}}</script><script src="/js/config.js" defer></script>

    <meta property="og:type" content="article">
<meta property="og:title" content="【Docker】之安装 ElasticSearch集群">
<meta property="og:url" content="https://www.xiaosige.com/post/65899326.html">
<meta property="og:site_name" content="小四儿">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://www.xiaosige.com/post/65899326/elk001.png">
<meta property="article:published_time" content="2022-10-13T11:06:38.000Z">
<meta property="article:modified_time" content="2022-10-13T21:47:22.561Z">
<meta property="article:author" content="leeze">
<meta property="article:tag" content="ElasticSearch">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://www.xiaosige.com/post/65899326/elk001.png">


<link rel="canonical" href="https://www.xiaosige.com/post/65899326.html">


<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://www.xiaosige.com/post/65899326.html","path":"post/65899326.html","title":"【Docker】之安装 ElasticSearch集群"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>【Docker】之安装 ElasticSearch集群 | 小四儿</title>
  

  <script src="/js/third-party/analytics/baidu-analytics.js" defer></script>
  <script async src="https://hm.baidu.com/hm.js?7a645cfcecaf8f711cd7518386adcc74"></script>







  
  <script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous" defer></script>
  <script src="https://cdn.jsdelivr.net/npm/@next-theme/pjax@0.6.0/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous" defer></script>
  <script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui@5.0.31/dist/fancybox/fancybox.umd.js" integrity="sha256-a+H7FYzJv6oU2hfsfDGM2Ohw/cR9v+hPfxHCLdmCrE8=" crossorigin="anonymous" defer></script>
  <script src="https://cdn.jsdelivr.net/npm/lozad@1.16.0/dist/lozad.min.js" integrity="sha256-mOFREFhqmHeQbXpK2lp4nA3qooVgACfh88fpJftLBbc=" crossorigin="anonymous" defer></script>
<script src="/js/utils.js" defer></script><script src="/js/motion.js" defer></script><script src="/js/sidebar.js" defer></script><script src="/js/next-boot.js" defer></script><script src="/js/pjax.js" defer></script>

  <script src="https://cdn.jsdelivr.net/npm/hexo-generator-searchdb@1.5.0/dist/search.js" integrity="sha256-xFC6PJ82SL9b3WkGjFavNiA9gm5z6UBxWPiu4CYjptg=" crossorigin="anonymous" defer></script>
<script src="/js/third-party/search/local-search.js" defer></script>

  <script class="next-config" data-name="pdf" type="application/json">{"object_url":{"url":"https://cdn.jsdelivr.net/npm/pdfobject@2.3.1/pdfobject.min.js","integrity":"sha256-jI72I8ZLVflVOisZIOaLvRew3tyvzeu6aZXFm7P7dEo="},"url":"/lib/pdf/web/viewer.html"}</script>
  <script src="/js/third-party/tags/pdf.js" defer></script>



  <script src="/js/third-party/fancybox.js" defer></script>



  
  <script data-pjax async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>




  <script src="https://cdn.jsdelivr.net/npm/quicklink@3.0.1/dist/quicklink.umd.js" integrity="sha256-44BednzIpUeQJcY8qtLyarFu0UCCTbgmWOvaoehiFQQ=" crossorigin="anonymous" defer></script>
  <script class="next-config" data-name="quicklink" type="application/json">{"enable":true,"home":true,"archive":true,"delay":true,"timeout":3000,"priority":true,"ignores":null,"url":"https://www.xiaosige.com/post/65899326.html"}</script>
  <script src="/js/third-party/quicklink.js" defer></script>
<!-- https://www.layuicdn.com/layui/css/layui.css -->
<script src="https://www.layuicdn.com/layui/layui.js"></script>

<script src="https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.min.js"></script>


<script src="https://cdn.jsdelivr.net/npm/gsap@3.12.4/dist/gsap.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/splitting@1.0.6/dist/splitting.min.js"></script>
<style type="text/css">
    .char{
      font-variation-settings: 'wght' var(--weight, 100);
      color: hsl(var(--hue), calc(var(--saturation) * 1%), 65%);
    }
</style>



<link rel="stylesheet" type="text/css" href="/css/shake.css" />


<link rel="stylesheet" type="text/css" href="/css/hover.css" />


<link rel="stylesheet" type="text/css" href="/zone/css/i_hover.css" />
<link rel="stylesheet" type="text/css" href="/css/injector/main.css" /><link rel="preload" as="style" href="/css/injector/light.css" /><link rel="preload" as="style" href="/css/injector/dark.css" />
  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>

<style>.github-emoji { position: relative; display: inline-block; width: 1.2em; min-height: 1.2em; overflow: hidden; vertical-align: top; color: transparent; }  .github-emoji > span { position: relative; z-index: 10; }  .github-emoji img, .github-emoji .fancybox { margin: 0 !important; padding: 0 !important; border: none !important; outline: none !important; text-decoration: none !important; user-select: none !important; cursor: auto !important; }  .github-emoji img { height: 1.2em !important; width: 1.2em !important; position: absolute !important; left: 50% !important; top: 50% !important; transform: translate(-50%, -50%) !important; user-select: none !important; cursor: auto !important; } .github-emoji-fallback { color: inherit; } .github-emoji-fallback img { opacity: 0 !important; }</style>
<link rel="alternate" href="/atom.xml" title="小四儿" type="application/atom+xml">
<link rel="alternate" href="/rss2.xml" title="小四儿" type="application/rss+xml"><!-- hexo-inject:begin --><!-- hexo-inject:end -->
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <!-- hexo-inject:begin --><!-- hexo-inject:end --><div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">小四儿</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">心之所愿，无所不至！</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签<span class="badge">61</span></a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类<span class="badge">25</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档<span class="badge">149</span></a></li><li class="menu-item menu-item-welfare"><a href="/welfare" rel="section"><i class="fa fa-star fa-fw"></i>收藏</a></li><li class="menu-item menu-item-music"><a href="/music" rel="section"><i class="fa fa-music fa-fw"></i>音乐</a></li><li class="menu-item menu-item-photos"><a href="/photos" rel="section"><i class="fa fa-camera-retro fa-fw"></i>相册</a></li><li class="menu-item menu-item-links"><a href="/links" rel="section"><i class="fa fa-link fa-fw"></i>友链</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
      <div class="search-header">
        <span class="search-icon">
          <i class="fa fa-search"></i>
        </span>
        <div class="search-input-container">
          <input autocomplete="off" autocapitalize="off" maxlength="80"
                placeholder="搜索..." spellcheck="false"
                type="search" class="search-input">
        </div>
        <span class="popup-btn-close" role="button">
          <i class="fa fa-times-circle"></i>
        </span>
      </div>
      <div class="search-result-container">
        <div class="search-result-icon">
          <i class="fa fa-spinner fa-pulse fa-5x"></i>
        </div>
      </div>
    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%87%86%E5%A4%87%E5%B7%A5%E4%BD%9C"><span class="nav-number">1.</span> <span class="nav-text">准备工作</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%8D%95%E8%8A%82%E7%82%B9%E9%85%8D%E7%BD%AE"><span class="nav-number">2.</span> <span class="nav-text">单节点配置</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E6%8B%89%E5%8F%96%E9%95%9C%E5%83%8F"><span class="nav-number">2.1.</span> <span class="nav-text">拉取镜像</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%88%9B%E5%BB%BA%E7%9B%AE%E5%BD%95"><span class="nav-number">2.2.</span> <span class="nav-text">创建目录</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#root-docker-elasticsearch-kibana-config-kibana-yml"><span class="nav-number">2.2.1.</span> <span class="nav-text">&#x2F;root&#x2F;docker&#x2F;elasticsearch&#x2F;kibana&#x2F;config&#x2F;kibana.yml</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#root-docker-elasticsearch-config-elasticsearch-yml"><span class="nav-number">2.2.2.</span> <span class="nav-text">&#x2F;root&#x2F;docker&#x2F;elasticsearch&#x2F;config&#x2F;elasticsearch.yml</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E6%9E%84%E5%BB%BA%E5%AE%B9%E5%99%A8%E5%B9%B6%E8%BF%90%E8%A1%8C"><span class="nav-number">2.3.</span> <span class="nav-text">构建容器并运行</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E8%AE%BE%E7%BD%AE%E6%8E%88%E6%9D%83%E8%AE%BF%E9%97%AE%E7%9A%84%E8%B4%A6%E5%8F%B7%E5%92%8C%E5%AF%86%E7%A0%81"><span class="nav-number">2.4.</span> <span class="nav-text">设置授权访问的账号和密码</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#%E5%BC%80%E5%90%AFx-pack%E9%AA%8C%E8%AF%81-root-docker-elasticsearchconfig-elasticsearch-yml-%E4%B8%AD%E6%B7%BB%E5%8A%A0%E5%A6%82%E4%B8%8B%E9%85%8D%E7%BD%AE"><span class="nav-number">2.4.1.</span> <span class="nav-text">开启x-pack验证,&#x2F;root&#x2F;docker&#x2F;elasticsearchconfig&#x2F;elasticsearch.yml 中添加如下配置</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E9%87%8D%E5%90%AFelasticsearch%E6%9C%8D%E5%8A%A1"><span class="nav-number">2.4.2.</span> <span class="nav-text">重启elasticsearch服务</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E8%AE%BE%E7%BD%AEelasticsearch%E5%AF%86%E7%A0%81"><span class="nav-number">2.4.3.</span> <span class="nav-text">设置elasticsearch密码</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E4%BF%AE%E6%94%B9elasticsearch%E5%AF%86%E7%A0%81"><span class="nav-number">2.4.4.</span> <span class="nav-text">修改elasticsearch密码</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E9%AA%8C%E8%AF%81"><span class="nav-number">2.4.5.</span> <span class="nav-text">验证</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#kinana-yml-%E4%BF%AE%E6%94%B9"><span class="nav-number">2.4.6.</span> <span class="nav-text">kinana.yml 修改</span></a></li></ol></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%A4%9A%E8%8A%82%E7%82%B9%E9%9B%86%E7%BE%A4%E9%85%8D%E7%BD%AE"><span class="nav-number">3.</span> <span class="nav-text">多节点集群配置</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%88%9B%E5%BB%BA%E7%9B%AE%E5%BD%95-1"><span class="nav-number">3.1.</span> <span class="nav-text">创建目录</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E7%BC%96%E5%86%99%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6-elasticsearch-yml"><span class="nav-number">3.2.</span> <span class="nav-text">编写配置文件(elasticsearch.yml)</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E7%BC%96%E5%86%99docker-compose-yml%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6"><span class="nav-number">3.3.</span> <span class="nav-text">编写docker-compose.yml配置文件</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8B%E9%9B%86%E7%BE%A4%E7%8A%B6%E6%80%81"><span class="nav-number">3.4.</span> <span class="nav-text">查看集群状态</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E4%BD%BF%E7%94%A8X-Pack%E8%AE%BE%E7%BD%AE%E6%8E%88%E6%9D%83%E5%8A%A0%E5%AF%86"><span class="nav-number">3.5.</span> <span class="nav-text">使用X-Pack设置授权加密</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#%E7%94%9F%E6%88%90%E8%AF%81%E4%B9%A6"><span class="nav-number">3.5.1.</span> <span class="nav-text">生成证书</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E9%9B%86%E7%BE%A4%E4%B8%AD%E7%9A%84%E4%BB%BB%E6%84%8F%E4%B8%80%E4%B8%AA%E8%8A%82%E7%82%B9%E7%94%9F%E6%88%90%E8%AF%81%E4%B9%A6%E5%92%8C%E7%A7%81%E9%92%A5"><span class="nav-number">3.5.2.</span> <span class="nav-text">集群中的任意一个节点生成证书和私钥</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E6%AD%A4%E6%97%B6%E5%B7%B2%E7%94%9F%E6%88%90%E8%AF%81%E4%B9%A6elastic-certificates-p12%EF%BC%8C%E5%B0%86%E8%AF%A5%E8%AF%81%E4%B9%A6%E5%A4%8D%E5%88%B6%E5%88%B0%E6%AF%8F%E4%B8%80%E4%B8%AA%E8%8A%82%E7%82%B9%E7%9A%84config-certs%E7%9B%AE%E5%BD%95%E4%B8%8B"><span class="nav-number">3.5.3.</span> <span class="nav-text">此时已生成证书elastic-certificates.p12，将该证书复制到每一个节点的config&#x2F;certs目录下</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E5%9C%A8docker-compose-yaml%E9%85%8D%E7%BD%AE%E5%A5%BD%E8%AF%81%E4%B9%A6%E6%98%A0%E5%B0%84"><span class="nav-number">3.5.4.</span> <span class="nav-text">在docker-compose.yaml配置好证书映射</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E4%BF%AE%E6%94%B9config-elasticsearch-yml%E6%9D%A5%E4%BD%BF%E7%94%A8%E5%8A%A0%E5%AF%86%E6%8E%88%E6%9D%83"><span class="nav-number">3.5.5.</span> <span class="nav-text">修改config&#x2F;elasticsearch.yml来使用加密授权</span></a></li></ol></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%97%AE%E9%A2%98"><span class="nav-number">4.</span> <span class="nav-text">问题</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#elasticsearch%E6%9F%A5%E7%9C%8B%E5%BD%93%E5%89%8D%E9%9B%86%E7%BE%A4%E4%B8%AD%E5%93%AA%E4%B8%AA%E8%8A%82%E7%82%B9%E6%98%AF%E4%B8%BB%E8%8A%82%E7%82%B9"><span class="nav-number">4.1.</span> <span class="nav-text">elasticsearch查看当前集群中哪个节点是主节点</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%8F%82%E8%80%83"><span class="nav-number">5.</span> <span class="nav-text">参考</span></a></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="leeze"
      src="https://static.xiaosige.com/img/avatar/avatar.jpg">
  <p class="site-author-name" itemprop="name">leeze</p>
  <div class="site-description" itemprop="description">因上努力，果上随缘！</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">149</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">25</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">61</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/leeze2012" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;leeze2012" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://www.teambition.com/" title="Teambition → https:&#x2F;&#x2F;www.teambition.com" rel="noopener me" target="_blank"><i class="fab fa-mixcloud fa-fw"></i>Teambition</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://gitee.com/leeze" title="Gitee → https:&#x2F;&#x2F;gitee.com&#x2F;leeze" rel="noopener me" target="_blank"><i class="fab fa-gg fa-fw"></i>Gitee</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://www.jianshu.com/u/e4c5daf92fa6" title="简书 → https:&#x2F;&#x2F;www.jianshu.com&#x2F;u&#x2F;e4c5daf92fa6" rel="noopener me" target="_blank"><i class="fab fa-telegram fa-fw"></i>简书</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://codeup.aliyun.com/" title="Codeup → https:&#x2F;&#x2F;codeup.aliyun.com" rel="noopener me" target="_blank"><i class="fab fa-envira fa-fw"></i>Codeup</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://blog.csdn.net/lileeze" title="CSDN → https:&#x2F;&#x2F;blog.csdn.net&#x2F;lileeze" rel="noopener me" target="_blank"><i class="fa fa-crosshairs fa-fw"></i>CSDN</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://dev.tencent.com/u/leeze" title="腾讯云 → https:&#x2F;&#x2F;dev.tencent.com&#x2F;u&#x2F;leeze" rel="noopener me" target="_blank"><i class="fab fa-jsfiddle fa-fw"></i>腾讯云</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://www.upyun.com/" title="又拍云 → https:&#x2F;&#x2F;www.upyun.com" rel="noopener me" target="_blank"><i class="fab fa-jsfiddle fa-fw"></i>又拍云</a>
      </span>
  </div>

<div class="site-overview-item animated" style="height:140px;">
    <div class="wrap">
        <div class="cup">
            <div class="cup__mouse"></div>
            <div class="cup__eyes"></div>
            <div class="cup__label">多喝水</div>
        </div>
        <div class="cup-shadow"></div>
    </div>
</div>

<style>

.wrap {
  width: 210px;
  height: 90px;
  -webkit-transform: translate(-50%, 50%);
          transform: translate(-50%, 50%);
  position: relative;
  left: 40%;
  /*top: 20%;*/
}

.cup {
  width: 140px;
  height: 100px;
  background: #FFF;
  box-shadow: inset 0px -10px 0 0 #EDDFE6;
  border-radius: 5px 5px 50px 50px;
  -webkit-transform-origin: bottom center;
          transform-origin: bottom center;
  -webkit-animation: .6s linear 0s infinite alternate cup;
          animation: .6s linear 0s infinite alternate cup;
  border: 3px solid #000;
  position: absolute;
  bottom: 0;
  left: 40px;
  z-index: 2;
}
.cup::before {
  content: '';
  width: 140px;
  background: #91ECED;
  height: 40px;
  border-radius: 100%;
  border: 3px solid #000;
  box-shadow: inset 0 20px 0 0 #fff;
  -webkit-animation: .6s linear 0s infinite alternate water;
          animation: .6s linear 0s infinite alternate water;
  position: absolute;
  top: -20px;
  left: -3px;
}
.cup::after {
  content: '';
  width: 22px;
  height: 26px;
  background: transparent;
  border-radius: 30% 100% 100% 30%;
  border: 3px solid #000;
  border-left: none;
  box-shadow: 4px 0 0 9px #fff, 6px 0 0 10px #000;
  position: absolute;
  bottom: 35px;
  right: -20px;
}
.cup__mouse {
  top: 45px;
  left: 45px;
  position: absolute;
  height: 30px;
  width: 50px;
  border: 3px solid #000;
  border-radius: 50%;
  -webkit-clip-path: polygon(50% 10%, 91% 100%, 5% 100%);
          clip-path: polygon(50% 10%, 91% 100%, 5% 100%);
}
.cup__eyes {
  width: 15px;
  height: 15px;
  background: #000;
  border-radius: 50%;
  box-shadow: 58px 0 0 0 #000;
  position: absolute;
  top: 55px;
  left: 35px;
}
.cup__label {
  width: 48px;
  height: 35px;
  box-sizing: content-box;
  /*padding-top: 10px;*/
  background: #ff7600;
  border: 2px solid #000;
  border-bottom: none;
  -webkit-transform-origin: top center;
          transform-origin: top center;
  -webkit-animation: .6s linear 0s infinite alternate label;
          animation: .6s linear 0s infinite alternate label;
  position: absolute;
  top: 40px;
  left: 45px;
  color: #fff
}
.cup__label::before {
  content: '';
  width: 3px;
  height: 15px;
  background: #000;
  -webkit-animation: .6s linear 0s infinite alternate label-line;
          animation: .6s linear 0s infinite alternate label-line;
  position: absolute;
  left: 25px;
  top: -16px;
}
.cup__label::after {
  content: '';
  position: absolute;
  left: -1px;
  bottom: 0;
  width: 0;
  height: 0;
  -webkit-filter: drop-shadow(0 -2px 0 black);
          filter: drop-shadow(0 -2px 0 black);
  border-bottom: 7px solid #fff;
  border-left: 26px solid transparent;
  border-right: 26px solid transparent;
}

.cup-shadow {
  width: 135px;
  height: 90px;
  background: #7CE589;
  border-radius: 40% 40% 100% 100%;
  -webkit-transform-origin: bottom center;
          transform-origin: bottom center;
  -webkit-animation: .6s linear 0s infinite alternate shadow;
          animation: .6s linear 0s infinite alternate shadow;
  position: absolute;
  bottom: -16px;
  left: 55px;
  z-index: 1;
}
.cup-shadow::after {
  content: '';
  width: 20px;
  height: 25px;
  background: transparent;
  border-radius: 30% 100% 100% 30%;
  border-left: none;
  box-shadow: 5px 0 0 5px #7CE589;
  position: absolute;
  bottom: 35px;
  right: -10px;
}

@-webkit-keyframes cup {
  0% {
    -webkit-transform: rotate(10deg);
            transform: rotate(10deg);
    box-shadow: inset -10px -10px 0 0 #EDDFE6;
  }
  100% {
    -webkit-transform: rotate(-10deg);
            transform: rotate(-10deg);
    box-shadow: inset 10px -10px 0 0 #EDDFE6;
  }
}

@keyframes cup {
  0% {
    -webkit-transform: rotate(10deg);
            transform: rotate(10deg);
    box-shadow: inset -10px -10px 0 0 #EDDFE6;
  }
  100% {
    -webkit-transform: rotate(-10deg);
            transform: rotate(-10deg);
    box-shadow: inset 10px -10px 0 0 #EDDFE6;
  }
}
@-webkit-keyframes water {
  0% {
    box-shadow: inset 30px 20px 0 0 #fff;
  }
  100% {
    box-shadow: inset -30px 20px 0 0 #fff;
  }
}
@keyframes water {
  0% {
    box-shadow: inset 30px 20px 0 0 #fff;
  }
  100% {
    box-shadow: inset -30px 20px 0 0 #fff;
  }
}
@-webkit-keyframes label {
  0% {
    -webkit-transform: rotate(40deg);
            transform: rotate(40deg);
  }
  100% {
    -webkit-transform: rotate(-40deg);
            transform: rotate(-40deg);
  }
}
@keyframes label {
  0% {
    -webkit-transform: rotate(40deg);
            transform: rotate(40deg);
  }
  100% {
    -webkit-transform: rotate(-40deg);
            transform: rotate(-40deg);
  }
}
@-webkit-keyframes label-line {
  0% {
    height: 15px;
    top: -16px;
  }
  25% {
    height: 22px;
    top: -22px;
  }
  50% {
    height: 15px;
    top: -16px;
  }
  100% {
    height: 22px;
    top: -22px;
  }
}
@keyframes label-line {
  0% {
    height: 15px;
    top: -16px;
  }
  25% {
    height: 22px;
    top: -22px;
  }
  50% {
    height: 15px;
    top: -16px;
  }
  100% {
    height: 22px;
    top: -22px;
  }
}
@-webkit-keyframes shadow {
  0% {
    -webkit-transform: skewX(-10deg);
            transform: skewX(-10deg);
  }
  100% {
    -webkit-transform: skewX(20deg);
            transform: skewX(20deg);
  }
}
@keyframes shadow {
  0% {
    -webkit-transform: skewX(-10deg);
            transform: skewX(-10deg);
  }
  100% {
    -webkit-transform: skewX(20deg);
            transform: skewX(20deg);
  }
}

.sidebar-panel{
    min-height: calc(var(--sidebar-wrapper-height) * 0.75);
}
.sidebar-toc-active .post-toc-wrap,
.sidebar-overview-active .site-overview-wrap {
  display: block;
}
</style>




<script src="/zone/js/canvasTime.js" async></script>
<div style="display:none;">
  <canvas id="canvas" style="width:60%;">当前浏览器不支持canvas，请更换浏览器后再试</canvas>
</div>
<style>
// 粒子时钟样式
.site-overview {
  text-align: center;
}

canvas#canvas {
  margin-top: 70px;
}
</style>


<div class="site-overview-item animated">
    <div style="">
        <iframe id="sjFrame" loading="lazy" src="/zone/tool/sj/index.html" border="0" width="100%" height="100" frameborder="no"> </iframe>
    </div>
</div>

        </div>
      </div>
    </div>

    
        <div class="pjax">
        </div>
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://www.xiaosige.com/post/65899326.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="https://static.xiaosige.com/img/avatar/avatar.jpg">
      <meta itemprop="name" content="leeze">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="小四儿">
      <meta itemprop="description" content="因上努力，果上随缘！">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="【Docker】之安装 ElasticSearch集群 | 小四儿">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          【Docker】之安装 ElasticSearch集群
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2022-10-13 19:06:38" itemprop="dateCreated datePublished" datetime="2022-10-13T19:06:38+08:00">2022-10-13</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2022-10-14 05:47:22" itemprop="dateModified" datetime="2022-10-14T05:47:22+08:00">2022-10-14</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Docker/" itemprop="url" rel="index"><span itemprop="name">Docker</span></a>
        </span>
    </span>

  
    <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="post-meta-item-text">阅读次数：</span>
      <span id="busuanzi_value_page_pv"></span>
    </span>



    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>13k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>12 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><img data-src="/post/65899326/elk001.png" style="box-shadow:none!important;">

<span id="more"></span>

<h3 id="准备工作"><a href="#准备工作" class="headerlink" title="准备工作"></a>准备工作</h3><div class="note info no-icon"><p>如果您的环境是Linux，注意要做以下操作，否则es可能会启动失败<br>1 用编辑工具打开文件<code>/etc/sysctl.conf</code><br>2 在尾部添加一行配置<code>vm.max_map_count = 262144</code>，如果已存在就修改，数值不能低于262144<br>3 修改保存，然后执行命令<code>sudo sysctl -p</code>使其立即生效</p>
</div>

<h3 id="单节点配置"><a href="#单节点配置" class="headerlink" title="单节点配置"></a>单节点配置</h3><h4 id="拉取镜像"><a href="#拉取镜像" class="headerlink" title="拉取镜像"></a>拉取镜像</h4><pre class="line-numbers language-docker" data-language="docker"><code class="language-docker">docker pull elasticsearch:7.17.6
docker pull kibana:7.17.6<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre>

<h4 id="创建目录"><a href="#创建目录" class="headerlink" title="创建目录"></a>创建目录</h4><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token comment"># 创建挂载目录</span>
<span class="token function">mkdir</span> <span class="token parameter variable">-p</span> /root/docker/elasticsearch/<span class="token punctuation">{</span>config,data,logs,plugins<span class="token punctuation">}</span>
<span class="token function">mkdir</span> <span class="token parameter variable">-p</span> /root/docker/elasticsearch/config/certs
<span class="token function">mkdir</span> <span class="token parameter variable">-p</span> kibana/config

<span class="token comment"># 创建配置文件</span>
<span class="token builtin class-name">echo</span> <span class="token string">"http.host: 0.0.0.0"</span> <span class="token operator">&gt;</span> /root/docker/elasticsearch/config/elasticsearch.yml

<span class="token comment"># 给挂载目录添加权限 chmod 777 -R /data/</span>
<span class="token function">chmod</span> <span class="token parameter variable">-R</span> <span class="token number">777</span> /root/docker/elasticsearch/data/<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h5 id="root-docker-elasticsearch-kibana-config-kibana-yml"><a href="#root-docker-elasticsearch-kibana-config-kibana-yml" class="headerlink" title="/root/docker/elasticsearch/kibana/config/kibana.yml"></a><code>/root/docker/elasticsearch/kibana/config/kibana.yml</code></h5><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#</span>
<span class="token comment"># ** THIS IS AN AUTO-GENERATED FILE **</span>
<span class="token comment">#</span>

<span class="token comment"># Default Kibana configuration for docker target</span>
server.name: kibana

server.host: <span class="token string">"0.0.0.0"</span>
server.shutdownTimeout: <span class="token string">"5s"</span>
elasticsearch.hosts: <span class="token punctuation">[</span> <span class="token string">"http://192.168.3.202:9200"</span> <span class="token punctuation">]</span>

monitoring.ui.container.elasticsearch.enabled: <span class="token boolean">true</span>

<span class="token comment"># 此处设置elastic的用户名和密码</span>
elasticsearch.username: <span class="token string">"elastic"</span>
elasticsearch.password: <span class="token string">"123456"</span>
<span class="token comment"># 设置kibana中文显示</span>
i18n.locale: <span class="token string">"zh-CN"</span>
<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h5 id="root-docker-elasticsearch-config-elasticsearch-yml"><a href="#root-docker-elasticsearch-config-elasticsearch-yml" class="headerlink" title="/root/docker/elasticsearch/config/elasticsearch.yml"></a><code>/root/docker/elasticsearch/config/elasticsearch.yml</code></h5><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">http.host: <span class="token number">0.0</span>.0.0

http.cors.enabled: <span class="token boolean">true</span>
http.cors.allow-origin: <span class="token string">"*"</span>

http.cors.allow-headers: Authorization
xpack.license.self_generated.type: basic

xpack.security.enabled: <span class="token boolean">true</span>
xpack.security.transport.ssl.enabled: <span class="token boolean">true</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>


<h4 id="构建容器并运行"><a href="#构建容器并运行" class="headerlink" title="构建容器并运行"></a>构建容器并运行</h4><pre class="line-numbers language-docker" data-language="docker"><code class="language-docker">docker run -d -p 9200:9200 -p 9300:9300 \
-e "discovery.type=single-node" \
-e ES_JAVA_OPTS="-Xms84m -Xmx512m" \
-v /root/docker/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v /root/docker/elasticsearch/data:/usr/share/elasticsearch/data \
-v /root/docker/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-v /root/docker/elasticsearch/logs:/usr/share/elasticsearch/logs \
--name elasticsearch \
elasticsearch:7.17.6 <span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>  或者直接利用<code>docker-compose.yml</code>文件，可以在容器运行后<code>拷贝</code>出配置<code>文件</code>等进行编辑然后挂载</p>
<pre class="line-numbers language-yaml" data-language="yaml"><code class="language-yaml"><span class="token key atrule">version</span><span class="token punctuation">:</span> <span class="token string">'3.9'</span>
<span class="token key atrule">services</span><span class="token punctuation">:</span>

  <span class="token key atrule">es01</span><span class="token punctuation">:</span>
    <span class="token key atrule">container_name</span><span class="token punctuation">:</span> es01
    <span class="token key atrule">image</span><span class="token punctuation">:</span> elasticsearch<span class="token punctuation">:</span>7.17.6
    <span class="token key atrule">ports</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> <span class="token string">"9200:9200"</span>
      <span class="token punctuation">-</span> <span class="token string">"9300:9300"</span>
    <span class="token key atrule">volumes</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> /root/docker/elasticsearch/config/elasticsearch.yml<span class="token punctuation">:</span>/usr/share/elasticsearch/config/elasticsearch.yml
      <span class="token punctuation">-</span> /root/docker/elasticsearch/data<span class="token punctuation">:</span>/usr/share/elasticsearch/data
      <span class="token punctuation">-</span> /root/docker/elasticsearch/logs<span class="token punctuation">:</span>/usr/share/elasticsearch/logs
    <span class="token key atrule">environment</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> TZ=Asia/Shanghai
    <span class="token comment">#  - "ES_JAVA_OPTS=-Xms1024m -Xmx2048m"</span>
      <span class="token punctuation">-</span> <span class="token string">"discovery.type=single-node"</span>
    <span class="token key atrule">restart</span><span class="token punctuation">:</span> always
    <span class="token key atrule">networks</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> elastic

  <span class="token key atrule">b01</span><span class="token punctuation">:</span>
    <span class="token key atrule">depends_on</span><span class="token punctuation">:</span> 
      <span class="token punctuation">-</span> es01
    <span class="token key atrule">image</span><span class="token punctuation">:</span> kibana<span class="token punctuation">:</span>7.17.6
    <span class="token key atrule">container_name</span><span class="token punctuation">:</span> kib01
    <span class="token key atrule">ports</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> 5601<span class="token punctuation">:</span><span class="token number">5601</span>
    <span class="token key atrule">environment</span><span class="token punctuation">:</span>
      <span class="token key atrule">ELASTICSEARCH_URL</span><span class="token punctuation">:</span> http<span class="token punctuation">:</span>//es01<span class="token punctuation">:</span><span class="token number">9200</span>
      <span class="token key atrule">ELASTICSEARCH_HOSTS</span><span class="token punctuation">:</span> http<span class="token punctuation">:</span>//es01<span class="token punctuation">:</span><span class="token number">9200</span>
    <span class="token key atrule">volumes</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> /root/docker/elasticsearch/kibana/config/kibana.yml<span class="token punctuation">:</span>/usr/share/kibana/config/kibana.yml
    <span class="token key atrule">networks</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> elastic

<span class="token key atrule">networks</span><span class="token punctuation">:</span>
  <span class="token key atrule">elastic</span><span class="token punctuation">:</span>
    <span class="token key atrule">driver</span><span class="token punctuation">:</span> bridge<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>



<h4 id="设置授权访问的账号和密码"><a href="#设置授权访问的账号和密码" class="headerlink" title="设置授权访问的账号和密码"></a>设置授权访问的账号和密码</h4><h5 id="开启x-pack验证-root-docker-elasticsearchconfig-elasticsearch-yml-中添加如下配置"><a href="#开启x-pack验证-root-docker-elasticsearchconfig-elasticsearch-yml-中添加如下配置" class="headerlink" title="开启x-pack验证,/root/docker/elasticsearchconfig/elasticsearch.yml 中添加如下配置"></a>开启<code>x-pack</code>验证,<code>/root/docker/elasticsearchconfig/elasticsearch.yml</code> 中添加如下配置</h5><pre class="line-numbers language-yaml" data-language="yaml"><code class="language-yaml"><span class="token comment"># 添加如下内容</span>

<span class="token comment"># 配置X-Pack</span>
<span class="token key atrule">http.cors.enabled</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
<span class="token key atrule">http.cors.allow-origin</span><span class="token punctuation">:</span> <span class="token string">"*"</span>
<span class="token key atrule">http.cors.allow-headers</span><span class="token punctuation">:</span> Authorization
<span class="token key atrule">xpack.security.enabled</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
<span class="token key atrule">xpack.license.self_generated.type</span><span class="token punctuation">:</span> basic
<span class="token key atrule">xpack.security.transport.ssl.enabled</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>  或</p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">bin/elasticsearch-certutil cert <span class="token parameter variable">-out</span> config/elastic-certificates.p12 <span class="token parameter variable">-pass</span> <span class="token string">""</span><span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<pre class="line-numbers language-yaml" data-language="yaml"><code class="language-yaml"><span class="token key atrule">xpack.security.enabled</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
<span class="token key atrule">xpack.security.transport.ssl.enabled</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
<span class="token key atrule">xpack.security.transport.ssl.verification_mode</span><span class="token punctuation">:</span> certificate
<span class="token key atrule">xpack.security.transport.ssl.keystore.path</span><span class="token punctuation">:</span> elastic<span class="token punctuation">-</span>certificates.p12
<span class="token key atrule">xpack.security.transport.ssl.truststore.path</span><span class="token punctuation">:</span> elastic<span class="token punctuation">-</span>certificates.p12<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h5 id="重启elasticsearch服务"><a href="#重启elasticsearch服务" class="headerlink" title="重启elasticsearch服务"></a>重启elasticsearch服务</h5><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token comment"># systemctl restart elasticsearch</span>
<span class="token function">docker</span> restart es01<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre>
<h5 id="设置elasticsearch密码"><a href="#设置elasticsearch密码" class="headerlink" title="设置elasticsearch密码"></a>设置elasticsearch密码</h5><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token comment"># 进入容器</span>
<span class="token function">docker</span> <span class="token builtin class-name">exec</span> <span class="token parameter variable">-it</span> es01 /bin/bash
<span class="token comment"># 重置密码</span>
<span class="token comment"># bin/elasticsearch-reset-password -u elastic</span>
<span class="token comment"># 自动生成好几个默认用户和密码</span>
bin/elasticsearch-setup-passwords auto 
<span class="token comment"># 如果想手动生成密码，则使用</span>
bin/elasticsearch-setup-passwords interactive <span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>  提示是否重置，输入<code>y</code>，控制台会打印新密码，<code>请记住这个密码，稍后要用到</code><br>  因为需要设置 elastic，apm_system，kibana，kibana_system，logstash_system，beats_system，remote_monitoring_user 这些用户的密码，故这个过程比较漫长，耐心设置；</p>
<h5 id="修改elasticsearch密码"><a href="#修改elasticsearch密码" class="headerlink" title="修改elasticsearch密码"></a>修改elasticsearch密码</h5><ol>
<li>知道原密码<br>  下面的示例为将<code>elastic</code>的密码设置为<code>"123456"</code>。<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token comment"># password 后为新密码, 控制台提示输入老密码</span>
<span class="token function">curl</span> <span class="token parameter variable">-H</span> <span class="token string">"Content-Type:application/json"</span> <span class="token parameter variable">-XPOST</span> <span class="token parameter variable">-u</span> elastic <span class="token string">'http://127.0.0.1:9200/_xpack/security/user/elastic/_password'</span> <span class="token parameter variable">-d</span> <span class="token string">'{ "password" : "123456" }'</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre>
  或<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token comment"># 不提示直接改</span>
<span class="token function">curl</span> <span class="token parameter variable">-XPOST</span> <span class="token parameter variable">--u</span> elastic:现密码 <span class="token string">"http://localhost:9200/_security/user/elastic/_password"</span> <span class="token parameter variable">-H</span> <span class="token string">'Content-Type: application/json'</span> <span class="token parameter variable">-d</span> <span class="token string">'{"password":"newpassword"}'</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre></li>
<li>忘记原密码<br>  修改配置文件<code>config/elasticsearch.yml</code>，注释掉支持<code>x-pack</code>的<code>xpack.security.enabled: true</code>配置，保存退出；<br>  重启Elasticsearch<br>  使用<code>curl</code>查看当前Elasticsearch的索引：<pre class="line-numbers language-none"><code class="language-none">curl -XGET "127.0.0.1:9200/_cat/indices" -H 'Content-Type: application/json'<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
  控制台打印，多了一个<code>.security-7</code>的索引，<code>删除``.security-7</code>的索引.<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">curl</span> <span class="token parameter variable">-XDELETE</span> <span class="token number">127.0</span>.0.1:9200/.security-7<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
  有如下打印，表示已成功删除：<pre class="line-numbers language-json" data-language="json"><code class="language-json"><span class="token punctuation">{</span><span class="token property">"acknowledged"</span><span class="token operator">:</span><span class="token boolean">true</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
  现在，重新设置elasticsearch密码。</li>
<li>用elasticsearch-users操作<br>  找回集群密码, 在 <code>Elasticsearch</code> 的安装目录下，有一个 utility 叫做 <code>elasticsearch-users</code>,我们可以使用这个工具找回我们的用户密码<br>  首先，我们来创建另外一个超级用户 <code>newadmin</code>：<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">bin/elasticsearch-users <span class="token function">useradd</span> newadmin <span class="token parameter variable">-p</span> password <span class="token parameter variable">-r</span> superuser<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
  我们接下来使用这个刚刚创建的超级用户来针对原有的 <code>elastic</code> 用户进行<code>重置密码</code>：<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">curl</span> <span class="token parameter variable">-s</span> <span class="token parameter variable">--user</span> newadmin:password <span class="token parameter variable">-XPUT</span> <span class="token string">"http://localhost:9200/_xpack/security/user/elastic/_password?pretty"</span> <span class="token parameter variable">-H</span> <span class="token string">'Content-Type: application/json'</span> <span class="token parameter variable">-d</span> <span class="token string">'{"password":"password1"}'</span><span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
  在上面，我们重置用户 <code>elastic</code> 的密码为 <code>password1</code>。我们可以通过如下的命令来检查我们是否可以通过这个重置的密码来对集群进行访问：<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">curl</span> <span class="token parameter variable">--user</span> elastic:password1 <span class="token parameter variable">-X</span> GET <span class="token string">"http://localhost:9200?pretty"</span><span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">$ <span class="token function">curl</span> <span class="token parameter variable">--user</span> elastic:password1 <span class="token parameter variable">-X</span> GET <span class="token string">"http://localhost:9200?pretty"</span>
<span class="token punctuation">{</span>
  <span class="token string">"name"</span> <span class="token builtin class-name">:</span> <span class="token string">"liuxg"</span>,
  <span class="token string">"cluster_name"</span> <span class="token builtin class-name">:</span> <span class="token string">"elasticsearch"</span>,
  <span class="token string">"cluster_uuid"</span> <span class="token builtin class-name">:</span> <span class="token string">"-vtUaRdHSnGJb5XdGC32bA"</span>,
  <span class="token string">"version"</span> <span class="token builtin class-name">:</span> <span class="token punctuation">{</span>
    <span class="token string">"number"</span> <span class="token builtin class-name">:</span> <span class="token string">"7.13.0"</span>,
    <span class="token string">"build_flavor"</span> <span class="token builtin class-name">:</span> <span class="token string">"default"</span>,
    <span class="token string">"build_type"</span> <span class="token builtin class-name">:</span> <span class="token string">"tar"</span>,
    <span class="token string">"build_hash"</span> <span class="token builtin class-name">:</span> <span class="token string">"5ca8591c6fcdb1260ce95b08a8e023559635c6f3"</span>,
    <span class="token string">"build_date"</span> <span class="token builtin class-name">:</span> <span class="token string">"2021-05-19T22:22:26.081971330Z"</span>,
    <span class="token string">"build_snapshot"</span> <span class="token builtin class-name">:</span> false,
    <span class="token string">"lucene_version"</span> <span class="token builtin class-name">:</span> <span class="token string">"8.8.2"</span>,
    <span class="token string">"minimum_wire_compatibility_version"</span> <span class="token builtin class-name">:</span> <span class="token string">"6.8.0"</span>,
    <span class="token string">"minimum_index_compatibility_version"</span> <span class="token builtin class-name">:</span> <span class="token string">"6.0.0-beta1"</span>
  <span class="token punctuation">}</span>,
  <span class="token string">"tagline"</span> <span class="token builtin class-name">:</span> <span class="token string">"You Know, for Search"</span>
<span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li>
</ol>
<h5 id="验证"><a href="#验证" class="headerlink" title="验证"></a>验证</h5><p>  浏览器直接访问<code>http://127.0.0.1:9200</code>,会出现输入用户名、密码的弹窗，输入elastic和密码后，才能看到elasticsearch信息；</p>
<h5 id="kinana-yml-修改"><a href="#kinana-yml-修改" class="headerlink" title="kinana.yml 修改"></a>kinana.yml 修改</h5><pre class="line-numbers language-yaml" data-language="yaml"><code class="language-yaml"><span class="token comment"># 末尾增加</span>
<span class="token key atrule">elasticsearch.username</span><span class="token punctuation">:</span> <span class="token string">"elastic"</span>
<span class="token key atrule">elasticsearch.password</span><span class="token punctuation">:</span> <span class="token string">"123456"</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre>




<h3 id="多节点集群配置"><a href="#多节点集群配置" class="headerlink" title="多节点集群配置"></a>多节点集群配置</h3><h4 id="创建目录-1"><a href="#创建目录-1" class="headerlink" title="创建目录"></a>创建目录</h4><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">mkdir</span> <span class="token parameter variable">-p</span> /root/docker/elasticsearch/node-1/<span class="token punctuation">{</span>data,logs,config,plugins<span class="token punctuation">}</span>
<span class="token function">mkdir</span> <span class="token parameter variable">-p</span> /root/docker/elasticsearch/node-2/<span class="token punctuation">{</span>data,logs,config,plugins<span class="token punctuation">}</span>
<span class="token function">mkdir</span> <span class="token parameter variable">-p</span> /root/docker/elasticsearch/node-3/<span class="token punctuation">{</span>data,logs,config,plugins<span class="token punctuation">}</span>
<span class="token function">mkdir</span> <span class="token parameter variable">-p</span> /root/docker/elasticsearch/kibana/config

<span class="token builtin class-name">cd</span> /root/docker/elasticsearch/
<span class="token comment"># 修改每个节点文件夹下data目录的权限(不修改后面会报错,权限不够)</span>
<span class="token function">chmod</span> <span class="token number">777</span> ./node-1/data/ <span class="token parameter variable">-R</span> 
<span class="token function">chmod</span> <span class="token number">777</span> ./node-1/logs/ <span class="token parameter variable">-R</span>
<span class="token function">chmod</span> <span class="token number">777</span> ./node-1/config/ <span class="token parameter variable">-R</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<h4 id="编写配置文件-elasticsearch-yml"><a href="#编写配置文件-elasticsearch-yml" class="headerlink" title="编写配置文件(elasticsearch.yml)"></a>编写配置文件(<code>elasticsearch.yml</code>)</h4><p>  新建<code>/root/docker/elasticsearch/node-1/config/elasticsearch.yml</code></p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">chmod</span> +x node-1/config/elasticsearch.yml<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<pre class="line-numbers language-yaml" data-language="yaml"><code class="language-yaml"><span class="token comment">#-------------------------------------------</span>
<span class="token comment"># es01</span>
<span class="token comment"># 集群的名称(各节点*集群名称*需要保持一致)</span>
<span class="token key atrule">cluster.name</span><span class="token punctuation">:</span> <span class="token string">"docker-cluster"</span>
<span class="token comment"># # # 节点的名称</span>
<span class="token key atrule">node.name</span><span class="token punctuation">:</span> node<span class="token punctuation">-</span><span class="token number">1</span>
<span class="token comment"># # # 此节点是否可以用作master节点</span>
<span class="token key atrule">node.master</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
<span class="token comment"># # # 此节点是否是存储节点</span>
<span class="token key atrule">node.data</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
<span class="token comment"># # # 此节点是否是预处理节点 如果是master节点的话 建议这里是true</span>
<span class="token key atrule">node.ingest</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
<span class="token comment">#设置主机IP 0.0.0.0时外网可以访问到</span>
<span class="token key atrule">network.host</span><span class="token punctuation">:</span> 0.0.0.0
<span class="token comment"># 配置端口</span>
<span class="token key atrule">http.port</span><span class="token punctuation">:</span> <span class="token number">9200</span>
<span class="token comment"># 集群通信端口</span>
<span class="token key atrule">transport.port</span><span class="token punctuation">:</span> <span class="token number">9300</span>
<span class="token comment">#集群内节点信息 每个节点会共享自己的此参数</span>
<span class="token key atrule">discovery.seed_hosts</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">"es01:9300"</span><span class="token punctuation">,</span><span class="token string">"es02:9300"</span><span class="token punctuation">,</span><span class="token string">"es03:9300"</span><span class="token punctuation">]</span>
<span class="token comment">#集群的master候选节点目录。只有在初始化的时候才生效。</span>
<span class="token comment">#这里只写node-1 并且配置这个参数 是用于快速搭建集群。集群已启动自动node-1   是master</span>
<span class="token key atrule">cluster.initial_master_nodes</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">"node-1"</span><span class="token punctuation">]</span>
<span class="token comment">#cross 跨域访问 配置这个之后 head就可以用了</span>
<span class="token key atrule">http.cors.enabled</span><span class="token punctuation">:</span>  <span class="token boolean important">true</span>
<span class="token key atrule">http.cors.allow-origin</span><span class="token punctuation">:</span>  <span class="token string">"*"</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<pre class="line-numbers language-yaml" data-language="yaml"><code class="language-yaml"><span class="token comment">#-------------------------------------------</span>
<span class="token comment"># es02</span>
<span class="token comment"># 集群的名称(各节点*集群名称*需要保持一致)</span>
<span class="token key atrule">cluster.name</span><span class="token punctuation">:</span> <span class="token string">"docker-cluster"</span>
<span class="token comment"># # # 节点的名称</span>
<span class="token key atrule">node.name</span><span class="token punctuation">:</span> node<span class="token punctuation">-</span><span class="token number">2</span>
<span class="token comment"># # # 此节点是否可以用作master节点</span>
<span class="token key atrule">node.master</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
<span class="token comment"># # # 此节点是否是存储节点</span>
<span class="token key atrule">node.data</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
<span class="token comment"># # # 此节点是否是预处理节点 如果是master节点的话 建议这里是true</span>
<span class="token key atrule">node.ingest</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
<span class="token comment">#设置主机IP 0.0.0.0时外网可以访问到</span>
<span class="token key atrule">network.host</span><span class="token punctuation">:</span> 0.0.0.0
<span class="token comment"># 配置端口</span>
<span class="token key atrule">http.port</span><span class="token punctuation">:</span> <span class="token number">9200</span>
<span class="token comment"># 集群通信端口</span>
<span class="token key atrule">transport.port</span><span class="token punctuation">:</span> <span class="token number">9300</span>
<span class="token comment">#集群内节点信息 每个节点会共享自己的此参数</span>
<span class="token key atrule">discovery.seed_hosts</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">"es01:9300"</span><span class="token punctuation">,</span><span class="token string">"es02:9300"</span><span class="token punctuation">,</span><span class="token string">"es03:9300"</span><span class="token punctuation">]</span>
<span class="token comment">#集群的master候选节点目录。只有在初始化的时候才生效。</span>
<span class="token comment">#这里只写node-1 并且配置这个参数 是用于快速搭建集群。集群已启动自动node-1   是master</span>
<span class="token key atrule">cluster.initial_master_nodes</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">"node-1"</span><span class="token punctuation">]</span>
<span class="token comment">#cross 跨域访问 配置这个之后 head就可以用了</span>
<span class="token key atrule">http.cors.enabled</span><span class="token punctuation">:</span>  <span class="token boolean important">true</span>
<span class="token key atrule">http.cors.allow-origin</span><span class="token punctuation">:</span>  <span class="token string">"*"</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<pre class="line-numbers language-yaml" data-language="yaml"><code class="language-yaml"><span class="token comment">#-------------------------------------------</span>
<span class="token comment"># es03</span>
<span class="token comment"># 集群的名称(各节点*集群名称*需要保持一致)</span>
<span class="token key atrule">cluster.name</span><span class="token punctuation">:</span> <span class="token string">"docker-cluster"</span>
<span class="token comment"># # # 节点的名称</span>
<span class="token key atrule">node.name</span><span class="token punctuation">:</span> node<span class="token punctuation">-</span><span class="token number">3</span>
<span class="token comment"># # # 此节点是否可以用作master节点</span>
<span class="token key atrule">node.master</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
<span class="token comment"># # # 此节点是否是存储节点</span>
<span class="token key atrule">node.data</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
<span class="token comment"># # # 此节点是否是预处理节点 如果是master节点的话 建议这里是true</span>
<span class="token key atrule">node.ingest</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
<span class="token comment">#设置主机IP 0.0.0.0时外网可以访问到</span>
<span class="token key atrule">network.host</span><span class="token punctuation">:</span> 0.0.0.0
<span class="token comment"># 配置端口</span>
<span class="token key atrule">http.port</span><span class="token punctuation">:</span> <span class="token number">9200</span>
<span class="token comment"># 集群通信端口</span>
<span class="token key atrule">transport.port</span><span class="token punctuation">:</span> <span class="token number">9300</span>
<span class="token comment">#集群内节点信息 每个节点会共享自己的此参数</span>
<span class="token key atrule">discovery.seed_hosts</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">"es01:9300"</span><span class="token punctuation">,</span><span class="token string">"es02:9300"</span><span class="token punctuation">,</span><span class="token string">"es03:9300"</span><span class="token punctuation">]</span>
<span class="token comment">#集群的master候选节点目录。只有在初始化的时候才生效。</span>
<span class="token comment">#这里只写node-1 并且配置这个参数 是用于快速搭建集群。集群已启动自动node-1   是master</span>
<span class="token key atrule">cluster.initial_master_nodes</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">"node-1"</span><span class="token punctuation">]</span>
<span class="token comment">#cross 跨域访问 配置这个之后 head就可以用了</span>
<span class="token key atrule">http.cors.enabled</span><span class="token punctuation">:</span>  <span class="token boolean important">true</span>
<span class="token key atrule">http.cors.allow-origin</span><span class="token punctuation">:</span>  <span class="token string">"*"</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<h4 id="编写docker-compose-yml配置文件"><a href="#编写docker-compose-yml配置文件" class="headerlink" title="编写docker-compose.yml配置文件"></a>编写<code>docker-compose.yml</code>配置文件</h4><pre class="line-numbers language-yaml" data-language="yaml"><code class="language-yaml"><span class="token key atrule">version</span><span class="token punctuation">:</span> <span class="token string">"3.9"</span>
<span class="token key atrule">services</span><span class="token punctuation">:</span>
  <span class="token key atrule">es01</span><span class="token punctuation">:</span>
    <span class="token key atrule">image</span><span class="token punctuation">:</span> elasticsearch<span class="token punctuation">:</span>7.17.6
    <span class="token key atrule">container_name</span><span class="token punctuation">:</span> es01
    <span class="token key atrule">privileged</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
    <span class="token key atrule">environment</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> bootstrap.memory_lock=true
      <span class="token punctuation">-</span> <span class="token string">"ES_JAVA_OPTS=-Xms512m -Xmx512m"</span>
      <span class="token punctuation">-</span> TZ=Asia/Shanghai
    <span class="token key atrule">ulimits</span><span class="token punctuation">:</span>
      <span class="token key atrule">memlock</span><span class="token punctuation">:</span>
        <span class="token key atrule">soft</span><span class="token punctuation">:</span> <span class="token number">-1</span>
        <span class="token key atrule">hard</span><span class="token punctuation">:</span> <span class="token number">-1</span>
    <span class="token key atrule">volumes</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> ./node<span class="token punctuation">-</span>1/data<span class="token punctuation">:</span>/usr/share/elasticsearch/data
      <span class="token punctuation">-</span> ./node<span class="token punctuation">-</span>1/config/elasticsearch.yml<span class="token punctuation">:</span>/usr/share/elasticsearch/config/elasticsearch.yml
    <span class="token key atrule">ports</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> 9201<span class="token punctuation">:</span><span class="token number">9200</span>
      <span class="token punctuation">-</span> 9301<span class="token punctuation">:</span><span class="token number">9300</span>
    <span class="token key atrule">networks</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> elastic

  <span class="token key atrule">es02</span><span class="token punctuation">:</span>
    <span class="token key atrule">image</span><span class="token punctuation">:</span> elasticsearch<span class="token punctuation">:</span>7.17.6
    <span class="token key atrule">container_name</span><span class="token punctuation">:</span> es02
    <span class="token key atrule">environment</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> bootstrap.memory_lock=true
      <span class="token punctuation">-</span> <span class="token string">"ES_JAVA_OPTS=-Xms512m -Xmx512m"</span>
      <span class="token punctuation">-</span> TZ=Asia/Shanghai
    <span class="token key atrule">ulimits</span><span class="token punctuation">:</span>
      <span class="token key atrule">memlock</span><span class="token punctuation">:</span>
        <span class="token key atrule">soft</span><span class="token punctuation">:</span> <span class="token number">-1</span>
        <span class="token key atrule">hard</span><span class="token punctuation">:</span> <span class="token number">-1</span>
    <span class="token key atrule">volumes</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> ./node<span class="token punctuation">-</span>2/data<span class="token punctuation">:</span>/usr/share/elasticsearch/data
      <span class="token punctuation">-</span> ./node<span class="token punctuation">-</span>2/config/elasticsearch.yml<span class="token punctuation">:</span>/usr/share/elasticsearch/config/elasticsearch.yml
    <span class="token key atrule">ports</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> 9202<span class="token punctuation">:</span><span class="token number">9200</span>
      <span class="token punctuation">-</span> 9302<span class="token punctuation">:</span><span class="token number">9300</span>
    <span class="token key atrule">networks</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> elastic  

  <span class="token key atrule">es03</span><span class="token punctuation">:</span>
    <span class="token key atrule">image</span><span class="token punctuation">:</span> elasticsearch<span class="token punctuation">:</span>7.17.6
    <span class="token key atrule">container_name</span><span class="token punctuation">:</span> es03
    <span class="token key atrule">environment</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> bootstrap.memory_lock=true
      <span class="token punctuation">-</span> <span class="token string">"ES_JAVA_OPTS=-Xms512m -Xmx512m"</span>
      <span class="token punctuation">-</span> TZ=Asia/Shanghai
    <span class="token key atrule">ulimits</span><span class="token punctuation">:</span>
      <span class="token key atrule">memlock</span><span class="token punctuation">:</span>
        <span class="token key atrule">soft</span><span class="token punctuation">:</span> <span class="token number">-1</span>
        <span class="token key atrule">hard</span><span class="token punctuation">:</span> <span class="token number">-1</span>
    <span class="token key atrule">volumes</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> ./node<span class="token punctuation">-</span>3/data<span class="token punctuation">:</span>/usr/share/elasticsearch/data
      <span class="token punctuation">-</span> ./node<span class="token punctuation">-</span>3/config/elasticsearch.yml<span class="token punctuation">:</span>/usr/share/elasticsearch/config/elasticsearch.yml
    <span class="token key atrule">ports</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> 9203<span class="token punctuation">:</span><span class="token number">9200</span>
      <span class="token punctuation">-</span> 9303<span class="token punctuation">:</span><span class="token number">9300</span>
    <span class="token key atrule">networks</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> elastic

  <span class="token key atrule">kibana</span><span class="token punctuation">:</span>
    <span class="token key atrule">image</span><span class="token punctuation">:</span> kibana<span class="token punctuation">:</span>7.17.6
    <span class="token key atrule">container_name</span><span class="token punctuation">:</span> kibana
    <span class="token key atrule">restart</span><span class="token punctuation">:</span> always
    <span class="token key atrule">ports</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> 5601<span class="token punctuation">:</span><span class="token number">5601</span>
    <span class="token key atrule">volumes</span><span class="token punctuation">:</span>
        <span class="token punctuation">-</span> ./kibana/config<span class="token punctuation">:</span>/usr/share/kibana/config
    <span class="token key atrule">environment</span><span class="token punctuation">:</span>
      <span class="token key atrule">I18N_LOCALE</span><span class="token punctuation">:</span> zh<span class="token punctuation">-</span>CN
      <span class="token key atrule">ELASTICSEARCH_URL</span><span class="token punctuation">:</span> http<span class="token punctuation">:</span>//es01<span class="token punctuation">:</span><span class="token number">9201</span>
      <span class="token key atrule">ELASTICSEARCH_HOSTS</span><span class="token punctuation">:</span> <span class="token string">'["http://es01:9201","http://es02:9202","http://es03:9203"]'</span>
      <span class="token key atrule">ELASTICSEARCH_SSL_VERIFICATIONMODE</span><span class="token punctuation">:</span> none
      <span class="token key atrule">ELASTICSEARCH_USERNAME</span><span class="token punctuation">:</span> elastic
      <span class="token key atrule">ELASTICSEARCH_PASSWORD</span><span class="token punctuation">:</span> abc
    <span class="token key atrule">networks</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> elastic 
      

<span class="token key atrule">networks</span><span class="token punctuation">:</span>
  <span class="token key atrule">elastic</span><span class="token punctuation">:</span>
    <span class="token key atrule">external</span><span class="token punctuation">:</span> <span class="token boolean important">true</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<h4 id="查看集群状态"><a href="#查看集群状态" class="headerlink" title="查看集群状态"></a>查看集群状态</h4><p>  <code>http://IP:9201/_cluster/health</code></p>
<h4 id="使用X-Pack设置授权加密"><a href="#使用X-Pack设置授权加密" class="headerlink" title="使用X-Pack设置授权加密"></a>使用X-Pack设置授权加密</h4><p>  按照<code>Elasticsearch</code>的要求，如果我们在<code>docker</code>的环境中启动<code>xpack.security.enabled</code>，我们必须也启动<code>xpack.security.transport.ssl.enabled</code>。否则，我们将会看到如下的错误信息：</p>
<div class="note info no-icon"><p>[1]:Transport SSL must be enabled if security is enabled on a [basic] license. Please set [xpack.security.transport.ssl.enabled] to [true] or disable security by setting [xpack.security.enabled] to [false]</p>
</div>
<p>  <code>X-Pack</code> 是 <code>ElasticSearch</code> 的一个插件，这个插件将提供与<code>ElasticSearch</code>来往的安全性。通过安装这个插件，我们就可以对 <code>ElasticSearch</code> 的集群节点生成证书，配置服务访问密码，以及使用TLS来确保HTTP客户端与集群之间的通信是加密的。</p>
<h5 id="生成证书"><a href="#生成证书" class="headerlink" title="生成证书"></a>生成证书</h5><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">docker</span> <span class="token builtin class-name">exec</span> <span class="token parameter variable">-it</span> es01 <span class="token function">bash</span><span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<p>  <code>进入容器</code>后，前往工作目录下（即<code>/usr/share/elasticsearch</code>），为Elasticearch集群创建一个证书颁发机构。使用<code>elasticsearch-certutil</code>命令输出一个<code>默认</code>名为<code>elastic-stack-ca.p12</code>的PKCS#12密钥存储库文件，它包含CA的公共证书和用于为每个节点签名证书的私钥。</p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token builtin class-name">cd</span> /usr/share/elasticsearch
./bin/elasticsearch-certutil ca<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre>
<div class="note info no-icon"><p>Please enter the desired output file [elastic-stack-ca.p12]:  此处按回车键<br>Enter password for elastic-stack-ca.p12 :  输入密码 snail(也可以不输入)</p>
</div>
<h5 id="集群中的任意一个节点生成证书和私钥"><a href="#集群中的任意一个节点生成证书和私钥" class="headerlink" title="集群中的任意一个节点生成证书和私钥"></a>集群中的<code>任意</code>一个节点生成证书和私钥</h5><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">./bin/elasticsearch-certutil cert <span class="token parameter variable">--ca</span> elastic-stack-ca.p12<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<div class="note info no-icon"><p>Enter password for CA (elastic-stack-ca.p12) : 输入上面的密码<br>Please enter the desired output file [elastic-certificates.p12]:  回车</p>
<p>Enter password for elastic-certificates.p12 : 输入上面的密码</p>
</div>
<h5 id="此时已生成证书elastic-certificates-p12，将该证书复制到每一个节点的config-certs目录下"><a href="#此时已生成证书elastic-certificates-p12，将该证书复制到每一个节点的config-certs目录下" class="headerlink" title="此时已生成证书elastic-certificates.p12，将该证书复制到每一个节点的config/certs目录下"></a>此时已生成证<code>书elastic-certificates.p12</code>，将该证书复制到<code>每一个节点</code>的<code>config/certs</code>目录下</h5><p>  上面的命令将使用我们的 CA 来生成一个证书 <code>elastic-certificates.p12</code>:<br>  执行<code>exit</code>退出容器，我们把上面的 <code>elastic-certificates.p12</code> 证书移至<code>./elasticsearch/config/certs</code>文件夹。</p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">docker</span> <span class="token function">cp</span> es01:/usr/share/elasticsearch/elastic-certificates.p12 ./elasticsearch/config/certs
<span class="token function">sudo</span> <span class="token function">chmod</span> <span class="token parameter variable">-R</span> <span class="token number">777</span> ./elasticsearch/config
<span class="token function">docker-compose</span> down<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre>
<h5 id="在docker-compose-yaml配置好证书映射"><a href="#在docker-compose-yaml配置好证书映射" class="headerlink" title="在docker-compose.yaml配置好证书映射"></a>在<code>docker-compose.yaml</code>配置好<code>证书</code>映射</h5><pre class="line-numbers language-yaml" data-language="yaml"><code class="language-yaml"><span class="token key atrule">volumes</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> ./elasticsearch/config/certs<span class="token punctuation">:</span>/usr/share/elasticsearch/config/certs<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre>
<h5 id="修改config-elasticsearch-yml来使用加密授权"><a href="#修改config-elasticsearch-yml来使用加密授权" class="headerlink" title="修改config/elasticsearch.yml来使用加密授权"></a>修改<code>config/elasticsearch.yml</code>来使用加密授权</h5><pre class="line-numbers language-yaml" data-language="yaml"><code class="language-yaml"><span class="token key atrule">cluster.name</span><span class="token punctuation">:</span> <span class="token string">"docker-cluster"</span>
<span class="token key atrule">network.host</span><span class="token punctuation">:</span> 0.0.0.0

<span class="token key atrule">http.cors.enabled</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
<span class="token key atrule">http.cors.allow-origin</span><span class="token punctuation">:</span> <span class="token string">"*"</span>
<span class="token key atrule">http.cors.allow-headers</span><span class="token punctuation">:</span> Authorization<span class="token punctuation">,</span>X<span class="token punctuation">-</span>Requested<span class="token punctuation">-</span>With<span class="token punctuation">,</span>Content<span class="token punctuation">-</span>Length<span class="token punctuation">,</span>Content<span class="token punctuation">-</span>Type


<span class="token key atrule">xpack.license.self_generated.type</span><span class="token punctuation">:</span> basic

<span class="token key atrule">xpack.security.enabled</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>

<span class="token comment"># 传输层通信:传输协议用于Elasticsearch节点之间的内部通信</span>
<span class="token key atrule">xpack.security.transport.ssl.enabled</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
<span class="token key atrule">xpack.security.transport.ssl.verification_mode</span><span class="token punctuation">:</span> certificate
<span class="token key atrule">xpack.security.transport.ssl.keystore.path</span><span class="token punctuation">:</span> certs/elastic<span class="token punctuation">-</span>certificates.p12
<span class="token key atrule">xpack.security.transport.ssl.truststore.path</span><span class="token punctuation">:</span> certs/elastic<span class="token punctuation">-</span>certificates.p12

<span class="token comment"># HTTP层通信:客户端到Elasticsearch集群的通信</span>
<span class="token key atrule">xpack.security.authc.api_key.enabled</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
<span class="token key atrule">xpack.security.http.ssl.enabled</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
<span class="token key atrule">xpack.security.http.ssl.keystore.path</span><span class="token punctuation">:</span> certs/elastic<span class="token punctuation">-</span>certificates.p12
<span class="token key atrule">xpack.security.http.ssl.truststore.path</span><span class="token punctuation">:</span> certs/elastic<span class="token punctuation">-</span>certificates.p12
<span class="token key atrule">xpack.security.http.ssl.verification_mode</span><span class="token punctuation">:</span> certificate

<span class="token key atrule">xpack.monitoring.collection.enabled</span><span class="token punctuation">:</span> <span class="token boolean important">false</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>  <code>verification_mode</code> 我们选择<code>certificate</code>，这个模式不会去检查证书的CN,只验证证书是否是信任机构签名的即可.如果我们需要验证,并且配置了IP，则需要把这个模式该为full<br>  如果证书是<code>PEM</code>格式，则使用下方配置</p>
<pre class="line-numbers language-yaml" data-language="yaml"><code class="language-yaml"><span class="token key atrule">xpack.security.transport.ssl.enabled</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
<span class="token key atrule">xpack.security.transport.ssl.verification_mode</span><span class="token punctuation">:</span> certificate 
<span class="token key atrule">xpack.security.transport.ssl.key</span><span class="token punctuation">:</span> /home/es/config/node01.key 
<span class="token key atrule">xpack.security.transport.ssl.certificate</span><span class="token punctuation">:</span> /home/es/config/node01.crt 
<span class="token key atrule">xpack.security.transport.ssl.certificate_authorities</span><span class="token punctuation">:</span> <span class="token punctuation">[</span> <span class="token string">"/home/es/config/ca.crt"</span> <span class="token punctuation">]</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span></span></code></pre>




<h3 id="问题"><a href="#问题" class="headerlink" title="问题"></a>问题</h3><h4 id="elasticsearch查看当前集群中哪个节点是主节点"><a href="#elasticsearch查看当前集群中哪个节点是主节点" class="headerlink" title="elasticsearch查看当前集群中哪个节点是主节点"></a><code>elasticsearch</code>查看当前集群中哪个节点是<code>主</code>节点</h4><p>  浏览器输入 : <code>http://ip:9200/_cat/nodes?v</code></p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">http://ip:9200/_cat/nodes?v
 
<span class="token comment"># 含有 * 的代表当前主节点</span>
 
<span class="token function">ip</span>            heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
<span class="token number">172.16</span>.16.188           <span class="token number">52</span>          <span class="token number">99</span>   <span class="token number">5</span>    <span class="token number">2.59</span>    <span class="token number">1.70</span>     <span class="token number">1.45</span> mdi       -      elastic3
<span class="token number">172.16</span>.16.187           <span class="token number">32</span>          <span class="token number">99</span>   <span class="token number">5</span>    <span class="token number">0.99</span>    <span class="token number">0.99</span>     <span class="token number">1.19</span> mdi       -      elastic2
<span class="token number">172.16</span>.16.231           <span class="token number">69</span>          <span class="token number">99</span>   <span class="token number">4</span>    <span class="token number">0.87</span>    <span class="token number">1.00</span>     <span class="token number">1.03</span> mdi       -      elastic4
<span class="token number">172.16</span>.21.28            <span class="token number">57</span>          <span class="token number">98</span>   <span class="token number">4</span>    <span class="token number">2.45</span>    <span class="token number">1.18</span>     <span class="token number">1.05</span> mdi       -      elastic5
<span class="token number">172.16</span>.21.29            <span class="token number">51</span>          <span class="token number">99</span>   <span class="token number">4</span>    <span class="token number">1.05</span>    <span class="token number">1.06</span>     <span class="token number">1.08</span> mdi       -      elastic6
<span class="token number">172.16</span>.16.186           <span class="token number">55</span>          <span class="token number">99</span>   <span class="token number">5</span>    <span class="token number">1.33</span>    <span class="token number">1.35</span>     <span class="token number">1.38</span> mdi       *      elastic1<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>  其中 <code>master</code> 列为 <code>*</code> 号表示该节点为<code>主节点</code>；如上所示为最后一行的 <code>elastic1</code> 为 <code>master</code> 节点。</p>
<h3 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h3><div class="note info no-icon"><p><a target="_blank" rel="noopener" href="http://junyao.tech/posts/c275ac42.html">docker-elk集群实践</a><br><a target="_blank" rel="noopener" href="https://blog.csdn.net/weixin_39555954/article/details/121683147"> Elasticsearch集群配置密码（传统方式&amp;Docker方式）</a><br><a target="_blank" rel="noopener" href="https://blog.csdn.net/smilelims/article/details/119488336">docker安装Elasticsearch+Kibana+密码配置</a><br><a target="_blank" rel="noopener" href="https://blog.csdn.net/Sunshine_Mr_Sun/article/details/126076588">Docker安装ELK详细步骤(生产试验,适用所有版本)</a><br><a target="_blank" rel="noopener" href="https://xinchen.blog.csdn.net/article/details/125196035">Docker下elasticsearch8部署、扩容、基本操作实战(含kibana)</a><br><a target="_blank" rel="noopener" href="https://xinchen.blog.csdn.net/article/details/125232858?spm=1001.2014.3001.5502">docker-compose快速部署elasticsearch-8.x集群+kibana</a></p>
</div><link rel="stylesheet" href="/css/spoiler.css" type="text/css"><script src="/js/spoiler.js" type="text/javascript" async></script>
    </div>

    
    
    

    <footer class="post-footer">
<div style="padding-top: 26px;">
    

    <div class="endlan">
        <i></i>
        <p>本文结束--- <img src="https://static.xiaosige.com/img/logo.png" style="display:inline-block;margin-bottom:-7px;height: 25px;"> ---感谢您的阅读</p>
    </div>


    <p id="hitokoto" style="text-align:center;margin-top: 30px;font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, STKaiti, KaiTi, SimKai, DFKai-SB, 'Lato', 'PingFang SC', 'Microsoft YaHei', sans-serif;font-weight: bold;color: #999;">
     正在加载一言...
    </p>
    <div style="margin-top: 30px;">
      <img id="wechat_subscriber_qcode" src="https://static.xiaosige.com/img/reward-container-back.png" alt="leeze wechat" style="max-width: 100%;">
    </div>
    

    
</div>


          <div class="reward-container">
  <div>请我一杯咖啡吧！</div>
  <button>
    打赏
  </button>
  <div class="post-reward">
      <div>
        <img src="https://static.xiaosige.com/img/wechatpay.png" alt="leeze 微信支付">
        <span>微信支付</span>
      </div>
      <div>
        <img src="https://static.xiaosige.com/img/alipay.png" alt="leeze 支付宝">
        <span>支付宝</span>
      </div>

  </div>
</div>

          

<div class="post-copyright">
<ul>
  <li class="post-copyright-author">
      <strong>原文作者： </strong>leeze
  </li>
  <li class="post-copyright-link">
      <strong>本文链接：</strong>
      <a href="https://www.xiaosige.com/post/65899326.html" title="【Docker】之安装 ElasticSearch集群">https://www.xiaosige.com/post/65899326.html</a>
  </li>
  <li class="post-copyright-license">
      <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/zh-CN" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>

          <div class="post-tags">
              <a href="/tags/ElasticSearch/" rel="tag"><i class="fa fa-tag"></i> ElasticSearch</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/post/90c0ce10.html" rel="prev" title="Centos8 安装VNC配置远程连接">
                  <i class="fa fa-angle-left"></i> Centos8 安装VNC配置远程连接
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/post/bd7f5796.html" rel="next" title="Harbor企业级私服Docker镜像仓库搭建">
                  Harbor企业级私服Docker镜像仓库搭建 <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






    <div class="comments" id="SOHUCS" sid="b88bb41302b897642d24af895eac4c22"></div>
</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 
    <span itemprop="copyrightYear">2025</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">Xiaosige.com 版权所有</span>
  </div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
    <span title="站点总字数">435k</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">6:35</span>
  </span>
</div>
<div class="busuanzi-count">
    <span class="post-meta-item" id="busuanzi_container_site_uv">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-item" id="busuanzi_container_site_pv">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>



<div calss="ypy" style="text-align:center;display:none;">
    本网站由
    <a target="_blank" rel="nofollow noopener" href="https://www.upyun.com/?utm_source=lianmeng&utm_medium=referral" style="border-bottom:none;">
        <img src="https://static.xiaosige.com/img/ypy_logo.png" style="display:inline-block;margin-bottom:-7px;height: 25px;-webkit-filter: brightness(.8);filter: brightness(.8);">
    </a>
    提供CDN加速/云存储服务
</div>


  <div class="beian">
          <img src="https://static.xiaosige.com/img/gongan.png" style="display: inline-block;vertical-align: text-bottom;padding-right: 6px;"><a href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=11011502004362" rel="noopener" target="_blank">京公网安备 11011502004362 </a>
    <span></span><a href="http://beian.miit.gov.cn/" rel="noopener" target="_blank">京ICP备2020038036号-1 </a>
    <span></span>
    本网站由
    <a target="_blank" rel="nofollow noopener" href="https://www.upyun.com/?utm_source=lianmeng&utm_medium=referral" style="border-bottom:none;">
        <img src="https://static.xiaosige.com/img/ypy_logo.png" style="display:inline-block;margin-bottom:-7px;height: 25px;-webkit-filter: brightness(.8);filter: brightness(.8);">
    </a>
    提供CDN加速/云存储服务
  </div>


<link href="https://cdn.jsdelivr.net/npm/aplayer@1.10.1/dist/APlayer.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/aplayer@1.10.1/dist/APlayer.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/meting@2.0.1/dist/Meting.min.js"></script>
<meting-js server="netease" type="playlist" id="2228518256" fixed="true" autoplay="false" order="random" lrc-type=1  theme="#eb7aab"></meting-js>


<div class="bg-box" id="bg-box1"></div>
<div class="bg-box" id="bg-box2"></div>
<style>
.bg-box {
 background-repeat:no-repeat;
 background-attachment:fixed;
 background-position:50% 50%;
 background-size:cover;
 position:fixed;
 left:0;
 right:0;
 top:0;
 bottom:0
}
#bg-box1 {
 z-index:-998
}
#bg-box2 {
 z-index:-999
}
</style>




    </div>
  </footer>

  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>
  <div class="sidebar-dimmer"></div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>
<script class="next-config" data-name="changyan" type="application/json">{"enable":true,"appid":"cyvSPOTJq","appkey":"4436699688bbb9caa6e8826551a7c0f7"}</script>
<script src="/js/third-party/comments/changyan.js" defer></script>
<!-- 提示信息 -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-toast-plugin@1.3.2/dist/jquery.toast.min.css"/>
<script src="https://cdn.jsdelivr.net/npm/jquery-toast-plugin@1.3.2/dist/jquery.toast.min.js"></script>
<!-- 樱花特效(https://cdn.jsdelivr.net/gh/yremp/yremp-js@1.5/sakura.js) -->
<!-- 下雪(圣诞) -->

<!-- 天气 -->

<!-- 文字闪烁（变色） -->
<script>
function magicColor(mode,t){
  t=t||10;
  let elem=document.getElementsByClassName("magic-color");
  if(!elem){
      setTimeout(function(){
          magicColor(mode,t-1);
      },400);
      return;
  }
  if(window.mcHandler==undefined){
      window.mcHandler={elements:[]};
      window.mcHandler.colorIndex=0;
      window.mcHandler.run=function(mode){
          let color=mode=="random"?("rgb("+Math.floor(Math.random()*256)+","+Math.floor(Math.random()*256)+","+Math.floor(Math.random()*256)+",1)"):["#CC0000","#9999CC","#CC3366","#669999","#FFCC00","#00CCCC","#CC00CC"][(window.mcHandler.colorIndex++)%7];
          for(var i=0,L=window.mcHandler.elements.length;i<L;i++)window.mcHandler.elements[i].style.color=color;
      }
  }
  window.mcHandler.elements=elem;
  if(window.mcHandler.timer==undefined){
      window.mcHandler.timer=setInterval(()=>{window.mcHandler.run(mode)},500);
  }
}
magicColor("random");//random为随机颜色，否则为固定颜色随机；上方“闪烁（变色）”字样为固定颜色随机
</script>


<!-- 一言API -->
<!-- 现代写法，推荐 -->
<!-- 兼容低版本浏览器 (包括 IE)，可移除 -->
<script src="https://cdn.jsdelivr.net/npm/bluebird@3.7.2/js/browser/bluebird.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/fetch@1.1.0/lib/fetch.min.js"></script>
<!--End-->
<script>
fetch('https://v1.hitokoto.cn')
  .then(function (res){
    return res.json();
  })
  .then(function (data) {
    var hitokoto = document.getElementById('hitokoto');
    if(hitokoto){
      hitokoto.innerHTML = "<i class='fa fa-volume-up magic-color' style='margin-right:6px;'></i>" + data.hitokoto + '——【' + data.from + '】';
    }
  })
  .catch(function (err) {
    console.error(err);
  })
</script>


<!-- 代码块自动隐藏 -->
<script>
$(function(){
    const CODE_MAX_HEIGHT = 200;
    const containers = [];

    // 展开
    $('body').on('click', '.js_unfold_code_btn', function () {
        $(this).closest('.js_highlight_container').addClass('on');
    });
    // 收起
    $('body').on('click', '.js_retract_code_btn', function () {
        const $container = $(this).closest('.js_highlight_container').removeClass('on');
        const winTop = $(window).scrollTop();
        const offsetTop = $container.offset().top;
        $(this).css('top', 0);
        if (winTop > offsetTop) {
            // 设置滚动条位置
            $('body, html').animate({
                scrollTop: $container.offset().top - CODE_MAX_HEIGHT
            }, 600);
        }
    });
    // 滚动事件，触发动画效果
    $(window).on('scroll', function () {
        const scrollTop = $(window).scrollTop();
        const temp = [];
        for (let i = 0; i < containers.length; i++) {
            const item = containers[i];
            const { $container, height, $hide, hasHorizontalScrollbar } = item;
            if ($container.closest('body').length === 0) {
                // 如果 $container 元素已经不在页面上, 则删除该元素
                // 防止pjax页面跳转之后，元素未删除
                continue;
            }
            temp.push(item);
            if (!$container.hasClass('on')) {
                continue;
            }
            const offsetTop = $container.offset().top;
            const hideBtnHeight = $hide.outerHeight();
            // 减去按钮高度，减去底部滚动条高度
            const maxTop = parseInt(height - (hasHorizontalScrollbar ? 17 : 0) - hideBtnHeight);
            let top = parseInt(
                Math.min(
                    Math.max(scrollTop - offsetTop, 0), // 如果小于 0 ，则取 0
                    maxTop,// 如果大于 height ，则取 height
                )
            );
            // 根据 sin 曲线设置"收起阅读"位置
            const halfHeight = parseInt($(window).height() / 2 * Math.sin((top / maxTop) * 90 * (2 * Math.PI/360)));
            $hide.css('top', Math.min(top + halfHeight, maxTop));
        }
        //containers = temp;
    });

    // 添加隐藏容器
    const addCodeWrap = ($node) => {
        const $container = $node.wrap('<div class="js_highlight_container highlight-container"><div class="highlight-wrap"></div></div>').closest('.js_highlight_container');

        // 底部 "阅读更多" 与 侧边栏 "收起阅读"
        const $btn = $(`
        <div class="highlight-footer">
          <a class="js_unfold_code_btn show-btn" href="javascript:;">
              <span class="btn-inner">
                阅读更多<i class="fa fa-angle-right fa-lg" aria-hidden="true"></i>
              </span>
              <div class="btnbg-x"></div>
          </a>
        </div>
        <a class="js_retract_code_btn hide-btn" href="javascript:;"><i class="fa fa-angle-up fa-lg" aria-hidden="true"></i>收起阅读</a>
      `);

        $container.append($btn);
        return $container;
    };

    $('.highlight').each(function () {
        // 防止重复渲染
        if (this.__render__ === true) {
            return true;
        }
        this.__render__ = true;
        const $this = $(this);
        const height = $(this).outerHeight();
        if (height > CODE_MAX_HEIGHT) {
            // 添加展开&收起容器
            const $container = addCodeWrap($this, height);
            containers.push({
                $container,
                height,
                $hide: $container.find('.js_retract_code_btn'),
                hasHorizontalScrollbar: this.scrollWidth > this.offsetWidth,
            });
        }
    });

    $('.line-numbers').each(function () {
        // 防止重复渲染
        if (this.__render__ === true) {
            return true;
        }
        this.__render__ = true;
        const $this = $(this);
        const height = $(this).outerHeight();
        if (height > CODE_MAX_HEIGHT) {
            // 添加展开&收起容器
            const $container = addCodeWrap($this, height);
            containers.push({
                $container,
                height,
                $hide: $container.find('.js_retract_code_btn'),
                hasHorizontalScrollbar: this.scrollWidth > this.offsetWidth,
            });
        }
    });

    $('.table-container').each(function () {
        // 防止重复渲染
        if (this.__render__ === true) {
            return true;
        }
        this.__render__ = true;
        const $this = $(this);
        const height = $(this).outerHeight();
        if (height > CODE_MAX_HEIGHT) {
            // 添加展开&收起容器
            const $container = addCodeWrap($this, height);
            containers.push({
                $container,
                height,
                $hide: $container.find('.js_retract_code_btn'),
                hasHorizontalScrollbar: this.scrollWidth > this.offsetWidth,
            });
        }
    });

});
</script>


<script  type="text/javascript">

layui.use(['jquery', 'layer'], function(){

  var $ = layui.$,layer = layui.layer;

  <!-- wobble窗口摆动特效 -->
  


     var wobbleWindow = function(object, params) {
          var canvas,
              ctx;
          var mousePos = {
              x: 0,
              y: 0
          };
          var isResizing = false;
          var delayId = 0;
          var canvasContent = {};
          var points = {};

          var settings = {};
          settings.name = 'wobblew'; //name
          settings.position = 'relative'; //relative or absolute
          settings.depth = -1; //depth for zIndex
          settings.overflowX = 'visible';
          settings.overflowY = 'visible';
          settings.offsetX = 0; //+ or - value the size of the div
          settings.offsetY = 0; //+ or - value the size of the div
          settings.moveTypeIn = 'move'; //method points follow the mouse
          settings.moveTypeOut = 'wobble'; //method points go back to init position
          settings.wobbleFactor = 0.95; //control the wobble effect
          settings.wobbleSpeed = 0.1; //control the wobble effect
          settings.moveSpeed = 6; //control the move speed
          settings.lineWidth = 1; //lineWidth

          settings.transplantLineColor = false; //true Use Object border-color
          settings.lineColor = ''; //no value = no line. Use hex/rgba values
          settings.transplantBodyColor = true; //true Use Object background Color
          settings.bodyColor = ''; //no value = no body color. Use hex/rgba values
          settings.radius = 50; //
          settings.pointCountX = 7; //quantity of points horizontal. must be an odd int
          settings.pointCountY = 5; //quantity of points vertical. must be an odd int
          settings.movementLeft = true; //enable/disable movement directions
          settings.movementRight = true; //enable/disable movement directions
          settings.movementTop = true; //enable/disable movement directions
          settings.movementBottom = true; //enable/disable movement directions
          settings.autoResize = true; //if true size will be automatically adjusted
          settings.debug = false; //enable/disable debug mode

          // ---
          if (params !== undefined) {
              for (var prop in params) {
                  if (params.hasOwnProperty(prop) && settings.hasOwnProperty(prop)) {
                      settings[prop] = params[prop];
                  }
              }
          }

          // ---
          if (!object) {
              throw Error('\n' + 'No div element found');
          }
          if ((settings.pointCountX % 2) === 0) {
              throw Error('\n' + 'Param pointCountX must be an odd integer');
          }
          if ((settings.pointCountY % 2) === 0) {
              throw Error('\n' + 'Param pointCountY must be an odd integer');
          }

          // ---
          HTMLElement.prototype.__defineGetter__("currentStyle", function() {
              return this.ownerDocument.defaultView.getComputedStyle(this, null);
          });
          // ---
          function init() {
              canvas = document.createElement('canvas');
              canvas.id = settings.name;
              canvas.style.position = 'absolute';
              canvas.style.zIndex = settings.depth.toString();
              canvas.addEventListener('mousemove', mouseMoveHandler);
              canvas.addEventListener('mouseleave', mouseLeaveHandler);
              ctx = canvas.getContext('2d');

              // element.insertBefore(canvas, element.firstChild);
              object.appendChild(canvas);
              object.style.position = settings.position;
              object.style.zIndex = (settings.depth + 1).toString();
              if (settings.overflowX.length > 0) {
                  object.parentElement.style.overflowX = settings.overflowX;
              };
              if (settings.overflowY.length > 0) {
                  object.parentElement.style.overflowY = settings.overflowY;
              };
              if (settings.transplantBodyColor) {
                  if (object.currentStyle.backgroundColor.length > 0) {
                      settings.bodyColor = object.currentStyle.backgroundColor;
                  }
              };
              if (settings.transplantLineColor) {
                  if (object.currentStyle.borderColor.length > 0) {
                      settings.lineColor = object.currentStyle.borderColor;
                  }
              };
              canvasContent.elementWidth = object.offsetWidth;
              canvasContent.elementHeight = object.offsetHeight;
              // ---
              resizeCanvas();
              addWindow();
              animloop();
              // -----------
              if (settings.transplantBodyColor) {
                  if (object.currentStyle.backgroundColor.length > 0) {
                      if (object.className.length > 0) {
                          object.className += ' wobbleTransparentBK';
                      } else {
                          object.className = ' wobbleTransparentBK';
                      };
                  }
              };
              if (settings.transplantLineColor) {
                  if (object.currentStyle.borderColor.length > 0) {
                      if (object.className.length > 0) {
                          object.className += ' wobbleTransparentLine';
                      } else {
                          object.className = ' wobbleTransparentLine';
                      };
                  }
              };
          };

          // ---
          function resizeCanvas() {
              canvasContent.width = canvasContent.elementWidth + settings.offsetX * 2;
              canvasContent.height = canvasContent.elementHeight + settings.offsetY * 2;

              if (settings.radius > 0) { //round,  ceil
                  settings.pointCountX = Math.round(canvasContent.width / settings.radius);
                  settings.pointCountY = Math.round(canvasContent.height / settings.radius);
              };
              if (settings.pointCountX % 2 == 0) {
                  settings.pointCountX = settings.pointCountX + 1;
              };
              if (settings.pointCountY % 2 == 0) {
                  settings.pointCountY = settings.pointCountY + 1;
              };

              points.spaceX = Math.min(canvasContent.elementWidth, canvasContent.width / (settings.pointCountX - 1));
              points.spaceY = Math.min(canvasContent.elementHeight, canvasContent.height / (settings.pointCountY + 1));
              points.radius = Math.ceil(Math.max(points.spaceX, points.spaceY));

              ///--------------new1------------------
              canvasContent.left = 0;
              canvasContent.top = 0;
              settings.canvasWidth = canvasContent.elementWidth;
              if (settings.movementLeft) {
                  canvas.style.left = -points.radius + 'px';
                  settings.canvasWidth += points.radius;
                  canvasContent.left = points.radius - settings.offsetX;
              } else {
                  canvas.style.left = -settings.offsetX + 'px';
              };
              if (settings.movementRight)
                  settings.canvasWidth += points.radius;

              settings.canvasHeight = canvasContent.elementHeight;
              if (settings.movementTop) {
                  canvas.style.top = -points.radius + 'px';
                  settings.canvasHeight += points.radius;
                  canvasContent.top = points.radius - settings.offsetY;
              } else {
                  canvas.style.top = -settings.offsetY + 'px';
              };
              if (settings.movementBottom)
                  settings.canvasHeight += points.radius;

              canvas.width = settings.canvasWidth;
              canvas.height = settings.canvasHeight;
          };

          // ---
          function addWindow() {
              points.pointHolder = [];
              // ---
              var point;
              var flag;
              var i,
                  l;
              // ---
              //top
              flag = true;
              for (i = 0, l = settings.pointCountX; i < l; i++) {
                  if (settings.movementTop) {
                      if (flag) {
                          point = addPoint(canvasContent.left + i * points.spaceX, canvasContent.top, 0, 0, 0, true, points.spaceX, 'P', settings.debug);
                          flag = false;
                      } else {
                          point = addPoint(canvasContent.left + i * points.spaceX, canvasContent.top, 0, 0, 0, true, points.spaceX, 'C', settings.debug);
                          flag = true;
                      }
                      if (i === 0 || i === l - 1) {
                          point.color = '#00FF00';
                          point.movement = false;
                      }
                      points.pointHolder.push(point);
                  } else {
                      if (i === 0 || i === l - 1) {
                          point = addPoint(canvasContent.left + i * points.spaceX, canvasContent.top, 0, 0, 0, false, 0, 'P', settings.debug);
                      }
                      points.pointHolder.push(point);
                  }
              }

              // ---
              //right
              flag = false;
              for (i = 1, l = settings.pointCountY + 1; i < l; i++) {
                  if (settings.movementRight) {
                      if (flag) {
                          point = addPoint(canvasContent.left + canvasContent.width, canvasContent.top + i * points.spaceY, 0, 0, 0, true, points.spaceY, 'P', settings.debug);
                          flag = false;
                      } else {
                          point = addPoint(canvasContent.left + canvasContent.width, canvasContent.top + i * points.spaceY, 0, 0, 0, true, points.spaceY, 'C', settings.debug);
                          flag = true;
                      }
                      points.pointHolder.push(point);
                  } else {
                      if (i === 1) {
                          point = addPoint(canvasContent.left + canvasContent.width, canvasContent.top + (i - 1) * points.spaceY, 0, 0, 0, false, 0, 'P', settings.debug);
                      } else if (i === settings.pointCountY) {
                          point = addPoint(canvasContent.left + canvasContent.width, canvasContent.top + (i + 1) * points.spaceY, 0, 0, 0, false, 0, 'P', settings.debug);
                      }
                      points.pointHolder.push(point);
                  }
              }

              // ---
              //bottom
              flag = true;
              for (i = settings.pointCountX - 1, l = -1; i > l; i--) {
                  if (settings.movementBottom) {
                      if (flag) {
                          point = addPoint(canvasContent.left + i * points.spaceX, canvasContent.top + canvasContent.height, 0, 0, 0, true, points.spaceX, 'P', settings.debug);
                          flag = false;
                      } else {
                          point = addPoint(canvasContent.left + i * points.spaceX, canvasContent.top + canvasContent.height, 0, 0, 0, true, points.spaceX, 'C', settings.debug);
                          flag = true;
                      }
                      if (i === 0 || i === settings.pointCountX - 1) {
                          point.color = '#00FF00';
                          point.movement = false;
                      }
                      points.pointHolder.push(point);
                  } else {
                      if (i === 0 || i === settings.pointCountX - 1) {
                          point = addPoint(canvasContent.left + i * points.spaceX, canvasContent.top + canvasContent.height, 0, 0, 0, false, 0, 'P', settings.debug);
                      }
                      points.pointHolder.push(point);
                  }
              }

              // ---
              //left
              flag = false;
              for (i = settings.pointCountY, l = -1; i > l; i--) {
                  if (settings.movementLeft) {
                      if (flag) {
                          point = addPoint(canvasContent.left, canvasContent.top + i * points.spaceY, 0, 0, 0, true, points.spaceY, 'P', settings.debug);
                          flag = false;
                      } else {
                          point = addPoint(canvasContent.left, canvasContent.top + i * points.spaceY, 0, 0, 0, true, points.spaceY, 'C', settings.debug);
                          flag = true;
                      }
                      points.pointHolder.push(point);
                  } else {
                      if (i === 0) {
                          point = addPoint(canvasContent.left, canvasContent.top + i * points.spaceY, 0, 0, 0, false, 0, 'P', settings.debug);
                      } else if (i === settings.pointCountY) {
                          point = addPoint(canvasContent.left, canvasContent.top + (i + 1) * points.spaceY, 0, 0, 0, false, 0, 'P', settings.debug);
                      }
                      points.pointHolder.push(point);
                  }
              }
          }

          // ---
          function addPoint(x, y, xp, yp, distance, movement, radius, type, visible) {
              var point = {};
              point.x = x;
              point.y = y;
              point.xp = x;
              point.yp = y;
              point.sx = 0;
              point.sy = 0;
              point.distance = distance;
              point.movement = movement;
              point.radius = radius;
              point.type = type;
              point.visible = visible;
              return point;
          };

          // ---
          window.requestAnimFrame = (function() {
              return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function(callback) {
                  window.setTimeout(callback, 1000 / 60);
              };
          })();

          function animloop() {
              requestAnimFrame(animloop);
              render();
              if (settings.autoResize) {
                  resize();
              }
          };

          // ---
          function render() {
              ctx.clearRect(0, 0, settings.canvasWidth, settings.canvasHeight);

              // ---
              var windowPoints = points.pointHolder;
              var i,
                  l;

              // ---
              ctx.beginPath();
              ctx.moveTo(windowPoints[0].x, windowPoints[0].y);
              for (i = 1, l = windowPoints.length; i < l; i += 2) {
                  var point = windowPoints[i];

                  // ---
                  var dx = mousePos.x - point.xp;
                  var dy = mousePos.y - point.yp;
                  point.distance = Math.sqrt(dx * dx + dy * dy);
                  if (point.distance < point.radius) {
                      if (settings.moveTypeIn === 'wobble') {
                          point.sx = point.sx * settings.wobbleFactor + (mousePos.x - point.x) * settings.wobbleSpeed;
                          point.sy = point.sy * settings.wobbleFactor + (mousePos.y - point.y) * settings.wobbleSpeed;
                          point.x = point.x + point.sx;
                          point.y = point.y + point.sy;
                      } else if (settings.moveTypeIn === 'move') {
                          point.x -= (point.x - mousePos.x) / settings.moveSpeed;
                          point.y -= (point.y - mousePos.y) / settings.moveSpeed;
                      }
                  } else {
                      if (settings.moveTypeOut === 'wobble') {
                          point.sx = point.sx * settings.wobbleFactor + (point.xp - point.x) * settings.wobbleSpeed;
                          point.sy = point.sy * settings.wobbleFactor + (point.yp - point.y) * settings.wobbleSpeed;
                          point.x = point.x + point.sx;
                          point.y = point.y + point.sy;
                      } else if (settings.moveTypeOut === 'move') {
                          point.x -= (point.x - point.xp) / settings.moveSpeed;
                          point.y -= (point.y - point.yp) / settings.moveSpeed;
                      }
                  }

                  // ---
                  var pointBefor = windowPoints[i - 1];
                  var pointAfter = windowPoints[i + 1];
                  if (i > 2 && i < windowPoints.length - 2) {
                      if (pointBefor.movement) {
                          pointBefor.x = (windowPoints[i - 2].x + point.x) / 2;
                          pointBefor.y = (windowPoints[i - 2].y + point.y) / 2;
                      }
                      if (pointAfter.movement) {
                          pointAfter.x = (windowPoints[i + 2].x + point.x) / 2;
                          pointAfter.y = (windowPoints[i + 2].y + point.y) / 2;
                      }
                  }
                  ctx.quadraticCurveTo(point.x, point.y, pointAfter.x, pointAfter.y);
              }

              // ---
              if (settings.lineColor.length > 0) {
                  ctx.lineWidth = settings.lineWidth;
                  ctx.strokeStyle = settings.lineColor;
                  ctx.stroke();
              }
              if (settings.bodyColor.length > 0) {
                  ctx.fillStyle = settings.bodyColor;
                  ctx.fill();
              }
              // ctx.globalCompositeOperation = 'source-out';
              // ctx.fillStyle = "rgba(0, 0, 0, 1)";
              // ctx.fill();

              // ---
              if (settings.debug) {
                  for (i = 0, l = windowPoints.length; i < l; i++) {
                      var point = windowPoints[i];
                      if (point.visible) {
                          if (point.type === 'P') {
                              drawCircle(point.x, point.y, 3, '#FF0000');
                          } else {
                              drawCircle(point.x, point.y, 6, '#FF00FF');
                          }
                          if (point.color) {
                              drawCircle(point.x, point.y, 12, point.color);
                          }
                      }
                  }
                  ctx.strokeStyle = '#000000';
                  ctx.strokeRect(0, 0, settings.canvasWidth, settings.canvasHeight);
              }
          };

          // ---
          function delayFlag() {
              resizeCanvas();
              addWindow();
              isResizing = false;
          };

          function resize() {
              if (!isResizing) {
                  if (canvasContent.elementWidth !== object.offsetWidth || canvasContent.elementHeight !== object.offsetHeight) {
                      // -----------
                      isResizing = true;
                      canvasContent.elementWidth = object.offsetWidth;
                      canvasContent.elementHeight = object.offsetHeight;
                      // 防止闪白
                      delayId = window.setTimeout(delayFlag, 10);
                  }
              }
          };

          // ---
          function drawCircle(x, y, radius, color) {
              ctx.beginPath();
              ctx.arc(x, y, radius, 0, 2 * Math.PI);
              ctx.strokeStyle = color;
              ctx.stroke();
          };

          // ---
          function mouseMoveHandler(event) {
              mousePos = getMousePos(canvas, event);
          };

          function mouseLeaveHandler(event) {
              mousePos.x = -10000;
              mousePos.y = -10000;
          };

          // ---
          function getMousePos(canvas, event) {
              var rect = canvas.getBoundingClientRect();
              return {
                  x: event.clientX - rect.left,
                  y: event.clientY - rect.top
              };
          };

          // ---
          init();
      };


  var settings = {
        radius: 20,
        wobbleFactor: 0.98,
        wobbleSpeed: 0.05,
        moveSpeed: 3,
        lineWidth: 3,
        lineColor: '#000',
        bodyColor: '#EEE'

  };
/*
  var footers=document.querySelectorAll(".footer");
  wobbleWindow(footers[footers.length-1],{
                radius: 20,
                depth:-2,
                movementBottom: false,
                movementLeft: false,
                movementRight: false,
                debug: false
  });*/

  var postblocks=document.querySelectorAll(".main-inner .post-block ");
  [].forEach.call(postblocks, function(elm) {
      wobbleWindow(elm,settings);
  });

  

});

</script>


<!-- 页面背景图片动态加载 -->
<script>

     //获取指定长度的uuid
     function uuid(len, radix) {
        var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
        var uuid = [], i;
        radix = radix || chars.length;

        if (len) {
          // Compact form
          for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random()*radix];
        } else {
          // rfc4122, version 4 form
          var r;

          // rfc4122 requires these characters
          uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
          uuid[14] = '4';

          // Fill in random data.  At i==19 set the high bits of clock sequence as
          // per rfc4122, sec. 4.1.5
          for (i = 0; i < 36; i++) {
            if (!uuid[i]) {
              r = 0 | Math.random()*16;
              uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
            }
          }
        }

        return uuid.join('');
    }

    function animatechangbgimg(elm,opacityvalue,bgimgurl){
        $(elm).animate(
        　　{opacity:opacityvalue},
        　　"slow",
        　　null,
        　　function(){
               $(elm).css("background-image","url("+bgimgurl+")");
        　　}
        );
    }

    function checktime(time){
        var oldtime = localStorage.getItem("pjax-imgurl-leeze-lastvisitedtime");
        return Math.floor(((new Date).getTime()-oldtime)/1e3) >= time;
    }

    function changbgimgurl(){

          if(checktime(13)){//每次打开新页面，都会触发一个新的调度器，固加入lastvisitedtime校验，确保循环时间
                //var tc = "https://cdn.jsdelivr.net/gh/maplesugarr/blog-assets/imgs/body-bg/body-bg-" + Math.floor(23 * Math.random()) + ".jpg";
                //var bgimgurl = 'https://source.unsplash.com/collection/30327996/2000x1000';
                //var initbgurl = null,newbgurl = "https://cdn.jsdelivr.net/gh/leeze2012/blog-assets/img/body-bg-" + Math.floor(26 * Math.random()) + ".jpg";
                var initbgurl = null,newbgurl = "https://static.xiaosige.com/img/bg/body-bg-" + Math.floor(26 * Math.random()) + ".jpg";
                if(localStorage.hasOwnProperty('pjax-imgurl-leeze')){
                  initbgurl = localStorage.getItem("pjax-imgurl-leeze");
                }else{
                  initbgurl = newbgurl;
                }

                if($("#bg-box1").css('opacity')==="1"){
                      animatechangbgimg("#bg-box1",0,newbgurl);
                      animatechangbgimg("#bg-box2",1,initbgurl);
                }else{
                      animatechangbgimg("#bg-box1",1,initbgurl);
                      animatechangbgimg("#bg-box2",0,newbgurl);
                }

                localStorage.setItem("pjax-imgurl-leeze", newbgurl);
                localStorage.setItem("pjax-imgurl-leeze-lastvisitedtime",(new Date).getTime());
          }

    };

    setInterval(changbgimgurl,15000);

</script>

<!-- 标题文字闪烁效果 -->
<script>

document.getElementsByClassName('site-title')[0].setAttribute('data-splitting','chars');

Splitting();
gsap.set('.char', {
  '--hue': gsap.utils.distribute({
    base: 0,
    amount: 330,
  })
});
gsap.to('.char', {
  '--weight': 700,
  '--saturation': 80,
  ease: 'sine.inOut',
  duration: 0.5,
  stagger: {
    yoyo: true,
    repeat: -1,
    each: 0.15,
  }
}).time(2);
</script>


<script type="text/javascript">
    $(document).ready(function() {
        <!-- 站点作者头像 -->
        if($('.site-author:first').children().first().prop("tagName").toLowerCase() === "img"){
            <!-- 头像站点作者头像连接到关于我 -->
            $('.site-author-image').prop('outerHTML', "<a href='/about' title='关于我'>"+$('.site-author-image').prop("outerHTML")+"</a>");
            <!-- 站点作者头像动画阴影 -->
            $(".site-author-image").hover(function(){
                $(this).toggleClass('site-author-image-yy');
            },function(){
                $(this).toggleClass('site-author-image-yy');
            });
        }
        <!-- 五星好评 -->
        if($("#wpac-rating").length > 0){
            $("#wpac-rating").before("<div style='color: rgba(0, 0, 0, 0.75); font-size:13px; letter-spacing:3px'>(&gt; 看完记得五星好评哦亲 &lt;)</div>");
            $(".wp_rating").css("height","30px");
        }
        if($(".copyright").length > 0){
            <!-- footer追加邮箱 -->
            if($(".leezeEmail").length === 0){
                $(".copyright").append("<span class='leezeEmail post-meta-item'><i style='margin-right:6px;' class='fa fa-fw fa-envelope with-love'></i><a href='mailto:leeze0216@163.com' title='E-Mail → mailto:leeze0216@163.com' target='_blank'>leeze0216@163.com</a></span>");
            }
            <!-- 版权图标 -->
            $(".copyright span[class='with-love']").css("display","none");
        }
        <!-- footer的阅读次数位置调整 -->
        if($(".busuanzi-count").length > 0){
            $(".wordcount").append($(".busuanzi-count").html());
            $(".busuanzi-count").remove();
        }
        <!-- 标签页追加抖动样式 -->
        if($('.tag-cloud-tags a').length > 0){
            $('.tag-cloud-tags a').each(function(){
              $(this).addClass('shake shake-slow');
            });
        }
        <!-- 社交链接增加hover样式 -->
        if($('.links-of-author-item a').length > 0){
            $('.links-of-author-item a').each(function(index,element){
                if((index+1)%2 === 1){
                    $(this).addClass('hvr-bounce-to-right');
                }else{
                    $(this).addClass('hvr-bounce-to-left');
                }
                if($(this).children('i').length > 0){
                    $(this).children('i').addClass('faa-spin');
                }
            });
        }
        <!-- 主菜单hover样式 -->
        if($('.main-menu .menu-item a').length > 0){
            $('.main-menu .menu-item a').each(function(index,element){
                $(this).addClass('hvr-grow-shadow');
                if($(this).children('i').length > 0){
                    $(this).children('i').addClass('faa-wrench');
                }
            });
        }
        <!-- 移动端 隐藏音乐 -->
        if (/(iPhone|iPad|iPod|iOS|Android)/i.test(navigator.userAgent)) {
            $('meting-js').css('display','none');
        }

        <!-- 转载 -->
        if($('.zhuanzai').length > 0){
            $('.zhuanzai').each(function(index,element){
                $(this).hover(function(){
                    var tipmsg = this.getAttribute('href');
                    if( tipmsg === 'javascript:;'){
                        tipmsg = "抱歉，忘记转载地址了！";
                    }
                    layer.tips(tipmsg, $(this), {
                      tips: 3
                    });
                },function(){
                    layer.closeAll('tips');
                });
            });
        }

    });
</script>
<!-- 自定义 -->
<script src="/zone/js/leeze.js"></script>
<div class="moon-menu">
  <div class="moon-menu-items">
    
    <div id="moon-menu-item-back2bottom" class="moon-menu-item" onclick="back2bottom()">
      <i class='fa fa-chevron-down'></i>    </div>
    
    <div id="moon-menu-item-back2top" class="moon-menu-item" onclick="back2top()">
      <i class='fa fa-chevron-up'></i>    </div>
    
  </div>
  <div class="moon-menu-button">
    <svg class="moon-menu-bg">
      <circle class="moon-menu-cricle" cx="50%" cy="50%" r="44%"></circle>
      <circle class="moon-menu-border" cx="50%" cy="50%" r="48%"></circle>
    </svg>
    <div class="moon-menu-content">
      <div class="moon-menu-icon"><i class='fas fa-ellipsis-v'></i></div>
      <div class="moon-menu-text"></div>
    </div>
  </div>
</div><script src="/js/injector.js"></script><!-- hexo-inject:begin --><!-- hexo-inject:end -->
</body>
</html>
